无法从Rstudio中的ggplot获取Plots

时间:2016-01-15 21:49:55

标签: r ggplot2 rstudio

我是R的新手。我一直致力于绘制数据,这工作正常,但突然之间,我根本没有在Rstudio中获得任何情节。我重新安装了Rstudio。我在代码中遗漏了什么吗?感谢

    library(ggplot2)
    library(Rmisc)
    SRL<-summarySE(CombinedwinrhizoSigmaPlot, measurevar="SLR", groupvars=c("Rootstock"))
    offset.v = -3
    offest.h = 0.5
    ggplot(SRL,aes(x=Roostock, y=SRL, ymax=70000, ymin = 0)) +
    geom_bar(stat="idendity",fill="gray50", colour="black", width = 0.7) +
    geom_errorbar(aes(ymax=SRL+se, ymin=SRL-se), width = 0.0, size=0.5, color = "black")+
    geom_text(aes(label=c("BC","BC","A","CDE","G","FG","EFG","CD","DEFG","CDEFG","AB","A","CD","CDEF","DEFG","CD","A","CDEFG"), hjust=offest.h, vjust=offest.v) +
   labs(x = "Rootstock", y = "Specific Root Length") + theme_bw() +
    theme(panel.grid.major.x = element_blank(),
    panel.grid.major.y = element_line(colour = "grey80"),
    plot.title = element_text(size = rel(1.5),
    face = "bold", vjust = 1.5),
    axis.title = element_text(face = "bold"),
    axis.title.y = element_text(vjust=1.8),
    axis.title.x = element_text(vjust= -0.5),
    panel.border = element_rect(colour="black")
   )

由于我无法附加.csv文件,这里是CombinedwinrhizoSigmaPlot的数据集,它只是部分的,因为它非常大,我无法附加它。 geom_text显然不正确,因为此样本数据集中的Rootstock数量少于总数量。谢谢!

    Rootstock   SLR
    A   33739.58824
    A   29812.64286
    A   29209
    A   31410.58824
    A   31833.39474
    A   18747.52381
    A   38536.79412
    A   25384.61702
    A   30997.22835
    A   17498.90625
    A   24195.32258
    A   23230.88158
    A   41197.3
    A   49207.17391
    A   49459.625
    A   48379.08333
    A   39909.5
    A   34406.26316
    A   34062.32
    A   41217.35417
    A   37801.85333
    A   32362.85235
    A   29592.44144
    A   41183.56311
    B   30143.42857
    B   36234.45455
    B   20233.33333
    B   37056
    B   28529.67568
    B   34542.05263
    B   37576.95238
    B   34754.15625
    B   20086.33333
    B   29096.5
    B   25690.225
    B   21062.61832
    B   38229.04167
    B   31150.44
    B   42008.95652
    B   40174.88571
    B   39374.97059
    B   34751.96296
    B   44326.18333
    B   35507.5283
    B   36021.58242
    B   40078.10744
    B   34904.34667
    B   34403.11594
    C   33633.44444
    C   30306
    C   44506
    C   24916.11111
    C   45506.75
    C   30893.53333
    C   63469.6
    C   29932.19231
    C   33791.26563
    C   21850.45714
    C   24615.34328
    C   29308.10484
    C   50217
    C   55341.42857
    C   54483.71429
    C   51372.22222
    C   50002.14286
    C   43051.16667
    C   49146.46667
    C   48473.44231
    C   32102.69298
    C   35886.97647
    C   34507.8
    C   45671.38636

1 个答案:

答案 0 :(得分:2)

这会奏效。还要感谢@Teja挑选一些拼写错误。

您的代码中还有一些其他拼写错误,下次要小心。我还在运行你的情节之前计算了你的上下条(似乎是ggplot2 v2的方法)。我没有包含你的geom_text()表达式,因为缺少一些文本,但是这段代码应该可以解决你的问题。

SRL$Lower <- SRL$SLR - SRL$se
SRL$Upper <- SRL$SLR + SRL$se

ggplot(SRL,aes(x=Rootstock, y=SLR)) +
    geom_bar(stat="identity",fill="gray50", colour="black", width = 0.7) + geom_errorbar(aes(ymax=Upper, ymin=Lower), size=0.5, color = "black") +    labs(x = "Rootstock", y = "Specific Root Length") + theme_bw() +
    theme(panel.grid.major.x = element_blank(),
          panel.grid.major.y = element_line(colour = "grey80"),
          plot.title = element_text(size = rel(1.5),
                                    face = "bold", vjust = 1.5),
          axis.title = element_text(face = "bold"),
          axis.title.y = element_text(vjust=1.8),
          axis.title.x = element_text(vjust= -0.5),
          panel.border = element_rect(colour="black")
    )
这个给予 enter image description here