R中的均值和sd的线图

时间:2018-01-15 00:03:15

标签: r plot line-plot

回答

如果显示环的加热曲线,我想做一个图,其中点具有平均值和标准偏差。 有数据:

mean_ring = c(25.81667, 16.29167, 17.99167, 19.25000, 19.90833, 20.81667)    
sd_ring = c(4.806025, 1.803259, 1.864724, 2.436652, 2.344610, 3.300918)    
time = c("Pre", 0, 5, 10, 15, 20)   
df_ring <- data.frame(mean_ring, sd_ring, time)
谢谢你!

1 个答案:

答案 0 :(得分:1)

会是这样的,

timeNumeric <- seq(-5, 20, 5)

# install.packages(c("tidyverse"), dependencies = TRUE)
library(ggplot2)

p <- ggplot(df_ring, aes(x= timeNumeric, y= mean_ring)) + 
       geom_line() + geom_point() + 
       geom_errorbar(aes(ymin = mean_ring-sd_ring, ymax= mean_ring + sd_ring), 
         width=.2, position=position_dodge(0.05))
p + labs(title="Heating curve of a ring", y="Mean temperature", x = "Time")  + 
       scale_x_time(breaks = timeNumeric, labels = time)

Heating curve of a ring