簡體   English   中英

使用 ggplot2 創建具有 95% CI 的平均加班時間變化的折線圖

[英]create a line graph using ggplot2 of the change in mean overtime with 95% CI

我的數據集是這樣的

df <- data.frame(time = c(0,0,1,1,2,2),
                 mean = c(8, 6, 7 , 6, 6, 5), 
                 group = c(1,0,1,0,1,0), 
                 lower = c(7, 5, 5, 4, 4, 4), 
                 upper = c(12, 9, 10, 8, 8, 8))

我想創建一個 plot 按組在 3 個時間點的平均值變化,每個都有相應的 95% CI(下,上),像這樣,y 軸是平均值,x 軸是時間

在此處輸入圖像描述

也許像這樣?

ggplot(df, aes(x = time, y = mean, group = group)) +
  geom_line(aes(lty = as.character(group)),
            position = position_dodge(width = 0.1)) +
  geom_errorbar(aes(ymax = upper, ymin = lower), width = 0.1,
                position = position_dodge(width = 0.1)) +
  geom_point(aes(shape = as.character(group)),
             position = position_dodge(width = 0.1)) +
  guides(lty = "none", shape = "none")

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM