R ggplot Barplot不是从0开始,ylim和coord_cartesian不起作用

时间:2016-02-29 12:43:17

标签: r ggplot2 bar-chart axis

我们正在研究一个生物学项目,该项目有几个不同的条件来种植植物,我们在制定我们想要的条形图方面遇到了一些困难。 我们的代码

inzet <- matrix(
    c("control", "zout", "anaeroob", "anaeroob en zout",
    mean.c, mean.z, mean.a, mean.az, st.c, st.z, st.a, st.az,
    high.c, high.z, high.a, high.az, low.c, low.z, low.a, low.az),
    nrow=4,    
    ncol=5,       #high and low are for creating the errorbars
    byrow=FALSE
)
behandeling <- c("control", "zout", "anaeroob", "anaeroob en zout")
dimnames(inzet)=list(c(1,2,3,4),c("behandeling", "mean", "st", "high", "low"))
inzet <- as.data.frame(inzet)

ggplot(inzet, aes(x=behandeling, y=mean)) + 
      coord_cartesian(ylim=c(0,40)) +  #this SHOULD fix the y-scale troubles
      geom_bar(stat="identity") + 
      geom_errorbar(aes(ymin=low, ymax=high),
            width=.2,                    # Width of the error bars
            position=position_dodge(.9)) 

给出了以下图表:

我们错过/忽视了什么,导致它从±17开始? 提前谢谢。

0 个答案:

没有答案