我有当前的代码:
library(plotrix)
upperlimit = c(6.77, 26.79, 29.29, 28.98)
lowerlimit = c(-7.31, 3.85, 4.13, 2.10)
mean = c(-0.27, 15.32, 16.71, 15.54)
df = data.frame(cbind(upperlimit,lowerlimit,mean))
plot(df$mean, ylim = c(-10,30), xlim = range(1,4))
plotCI(df$mean,y=NULL, uiw=df$upperlimit-df$mean, liw=df$mean-df$lowerlimit, err="y", pch=20, scol = "black", add=TRUE)
abline(a= 0, b= 0, col="red", lty=3)
这给了我一个置信区间的箱线图:
但是,我希望水平轴显示“中午”,“下午3点”,“下午6点”,“晚上9点”。这可能吗? (或者我必须使用ggplot)?
我尝试修改从xlim = range(1,4)
到xlim = c("noon", "3pm", "6pm", "9pm")
的行,但它不起作用。
答案 0 :(得分:3)
只需关闭默认的x轴(使用xaxt="n"
)并自行绘制(指定所需的labels=
)
plot(df$mean, ylim = c(-10,30), xlim = range(1,4), xaxt="n")
plotCI(df$mean,y=NULL, uiw=df$upperlimit-df$mean, liw=df$mean-df$lowerlimit, err="y",
pch=20, scol = "black", add=TRUE)
abline(a= 0, b= 0, col="red", lty=3)
axis(side=1, at=1:4, labels=c("noon", "3pm", "6pm", "9pm"))