【问题标题】:Trouble with x-axis and error bars (line graph with two lines) in ggplot2ggplot2中的x轴和误差线(两条线的折线图)有问题
【发布时间】:2019-02-20 21:23:23
【问题描述】:

以下数据:

我的 x 轴出现问题,因为在我运行代码时它失去了顺序。我正在寻找一个从 1 到 14 的轴(级别为 1 t0 14)。

R 格式数据汇总:

chlo <- data.frame(Culture=rep(c("Axenix", "Mixed"), each=14),
                   Time=rep(c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"),2),
                   Growth=c(4246443, 5863739, 10599835, 19379643, 23071353, 26763062,   29143319,   30373889,   32800365,   34080042,   35359719,   36642284,   38629683,   39663824, 4238613,  3983333, 8383333, 11266667, 14600000,   17933333,   23400000,   25866667,   29333333,   32116667,   34900000,   42833333,   50200000,   54200000))

str(chlo)

看层次

chlo$Time
1  2  3  4  5  6  7  8  9  10 11 12 13 14 1  2  3  4  5  6  7  8  9  10 11 12 13 14
Levels: 1 10 11 12 13 14 2 3 4 5 6 7 8 9

我也无法添加垂直标准偏差条:

对于前 1 到 14 个值(Axenic),各自的 sd 是:(+ & -):

249116, 960902, 2712164,    991667, 914799, 843048, 1826696,    2050218, 3457363,   3664220,    3876349,    4410793, 5123502,   5193421

对于第二组值 1 到 14(混合)值,各自的 sd 是 (+ & -):

44621,  980221, 1871719,    332916, 326917, 321455, 4200000,    2013289,    2386071,    2559460,    3207803,    2773686,    2170253, 5102940

【问题讨论】:

    标签: r ggplot2 standard-deviation linegraph


    【解决方案1】:

    Time 是一个连续度量,应该是数字:

    chlo$Time<-as.numeric(chlo$Time)
    
    # install.packages("ggplot2") #uncomment and run if you don't have this package
    library(ggplot2)
    ggplot(chlo,aes(x=Time,y=Growth, colour=Culture))+
      geom_point()+
      geom_line()
    

    误差线问题是一个单独的问题,已经被问过很多次了,搜索geom_errorbars()函数。

    http://www.sthda.com/english/wiki/ggplot2-error-bars-quick-start-guide-r-software-and-data-visualization

    【讨论】: