2017-04-03 49 views
0

我當前的代碼:在情節更改水平軸中的R

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) 

這讓我置信區間的箱線圖:

enter image description here

不過,我想橫軸,以顯示「中午」,「下午3點」,「下午6點」,「下午9點」。這可能嗎? (或者我必須使用ggplot)?

我試圖修改從xlim = range(1,4)xlim = c("noon", "3pm", "6pm", "9pm")的行,但它不起作用。

回答

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")) 

enter image description here