Skip to content

Commit 70380b3

Browse files
author
Lukas Bütikofer
committed
plot reference line before data
1 parent 730f4d9 commit 70380b3

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: forplot
22
Title: Forest plots
3-
Version: 0.0.2
3+
Version: 0.0.3
44
Authors@R:
55
person("Lukas", "Bütikofer", , "lukas.buetikofer@unibe.ch", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-0801-746X"))

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ ordering of columns according to input
66

77
forplot 0.0.2
88
------------------
9+
bug fix in help file
910

10-
bug fix in help file
11+
forplot 0.0.3
12+
------------------
13+
plotting reference line before data

R/forest.R

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#************************************#
22
#* Function for forest plots
33
#* Author: Lukas Buetikofer
4-
#* Date created: 03.05.2018
5-
#* Last update: November 2020
4+
#* Date created: 2018-05-03
5+
#* Last update: 2025-12
66
#* **********************************#
77

88
#' forest
@@ -319,6 +319,23 @@ fplot<-function(dat,
319319
#%%%%%%%%%%%
320320

321321
plot(0,type="n",xlim=xlim,ylim=ylim,yaxt="n",ylab="",xlab="",axes=FALSE)
322+
323+
#lines and axis
324+
if (!is.na(ref[["x"]])) {
325+
lines(x=rep(ref[["x"]],2),y=c(ylim[1]-shift_ymin+shift_xaxis,ylim[2]+shift_ymax+ref[["extend"]]),
326+
lty=ref[["lty"]],col=ref[["col"]],lwd=ref[["lwd"]])
327+
}
328+
if (sum(!is.na(xlab_text))==0) {
329+
xlab_text<-xlab
330+
}
331+
axis(side=1,pos=shift_xaxis,at=xlab,labels=rep("",length(xlab)),las=1,tick=TRUE,tck=tck,lwd=lwd)
332+
mtext(side=1,line=xlab_line,at=xlab,text=xlab_text,cex=xlab_cex)
333+
334+
if (!is.na(bottomline)) {
335+
lines(x=c(par("usr")[1],par("usr")[2]),y=c(shift_xaxis,shift_xaxis),xpd=TRUE)
336+
}
337+
338+
#points and arrows
322339
#symbols(dat$beta,y.at,squares=1/dat$beta_se,add=TRUE,inches=0.15,bg=pcol,fg=NA)
323340
points(dat$beta,y.at,pch=ps[["pch"]],cex=ps[["cex"]],col=ps[["col"]])
324341
arrows(y0=y.at,y1=y.at,x0=dat$beta_lci,x1=dat$beta_uci,code=3,angle=90,length=0)
@@ -353,26 +370,15 @@ fplot<-function(dat,
353370
arrows(y0=y.at,y1=y.at,x0=dat$beta_lci,x1=dat$beta_uci,code=3,angle=90,length=cap_length)
354371
}
355372

356-
#lines and axis
357-
if (!is.na(ref[["x"]])) {
358-
lines(x=rep(ref[["x"]],2),y=c(ylim[1]-shift_ymin+shift_xaxis,ylim[2]+shift_ymax+ref[["extend"]]),
359-
lty=ref[["lty"]],col=ref[["col"]],lwd=ref[["lwd"]])
360-
}
361-
if (sum(!is.na(xlab_text))==0) {
362-
xlab_text<-xlab
363-
}
364-
axis(side=1,pos=shift_xaxis,at=xlab,labels=rep("",length(xlab)),las=1,tick=TRUE,tck=tck,lwd=lwd)
365-
mtext(side=1,line=xlab_line,at=xlab,text=xlab_text,cex=xlab_cex)
366-
367-
if (!is.na(bottomline)) {
368-
lines(x=c(par("usr")[1],par("usr")[2]),y=c(shift_xaxis,shift_xaxis),xpd=TRUE)
369-
}
373+
370374

371375
#2nd beta:
372376
##########
373-
374-
#text:
375377
if (!is.null(beta2)) {
378+
379+
#2nd beta text:
380+
##########
381+
376382
plot(0,type="n",xlim=c(0,1),ylim=ylim,yaxt="n",ylab="",xlab="",axes=FALSE)
377383
if (sum(grepl("beta_format2",colnames(dat)))==0) {
378384
if (lscale) {
@@ -390,9 +396,26 @@ fplot<-function(dat,
390396
lines(x=c(par("usr")[1],par("usr")[2]),y=c(shift_xaxis,shift_xaxis),xpd=TRUE)
391397
}
392398

393-
#beta2
394-
399+
#2nd beta
400+
#######
395401
plot(0,type="n",xlim=xlim2,ylim=ylim,yaxt="n",ylab="",xlab="",axes=FALSE)
402+
403+
#lines and axis
404+
if (!is.na(ref[["x"]])) {
405+
lines(x=rep(ref[["x"]],2),y=c(ylim[1]-shift_ymin+shift_xaxis,ylim[2]+shift_ymax+ref[["extend"]]),
406+
lty=ref[["lty"]],col=ref[["col"]],lwd=ref[["lwd"]])
407+
}
408+
if (sum(!is.na(xlab_text2))==0) {
409+
xlab_text2<-xlab2
410+
}
411+
axis(side=1,pos=shift_xaxis,at=xlab2,labels=rep("",length(xlab2)),las=1,tick=TRUE,tck=tck,lwd=lwd)
412+
mtext(side=1,line=xlab_line,at=xlab2,text=xlab_text2,cex=xlab_cex)
413+
414+
if (!is.na(bottomline)) {
415+
lines(x=c(par("usr")[1],par("usr")[2]),y=c(shift_xaxis,shift_xaxis),xpd=TRUE)
416+
}
417+
418+
#points and arrows
396419
points(dat$beta2,y.at,pch=ps[["pch"]],cex=ps[["cex"]],col=ps[["col"]])
397420
arrows(y0=y.at,y1=y.at,x0=dat$beta_lci2,x1=dat$beta_uci2,code=3,angle=90,length=0)
398421

@@ -426,20 +449,7 @@ fplot<-function(dat,
426449
arrows(y0=y.at,y1=y.at,x0=dat$beta_lci2,x1=dat$beta_uci2,code=3,angle=90,length=cap_length)
427450
}
428451

429-
#lines and axis
430-
if (!is.na(ref[["x"]])) {
431-
lines(x=rep(ref[["x"]],2),y=c(ylim[1]-shift_ymin+shift_xaxis,ylim[2]+shift_ymax+ref[["extend"]]),
432-
lty=ref[["lty"]],col=ref[["col"]],lwd=ref[["lwd"]])
433-
}
434-
if (sum(!is.na(xlab_text2))==0) {
435-
xlab_text2<-xlab2
436-
}
437-
axis(side=1,pos=shift_xaxis,at=xlab2,labels=rep("",length(xlab2)),las=1,tick=TRUE,tck=tck,lwd=lwd)
438-
mtext(side=1,line=xlab_line,at=xlab2,text=xlab_text2,cex=xlab_cex)
439-
440-
if (!is.na(bottomline)) {
441-
lines(x=c(par("usr")[1],par("usr")[2]),y=c(shift_xaxis,shift_xaxis),xpd=TRUE)
442-
}
452+
443453
}
444454

445455
#p columns

0 commit comments

Comments
 (0)