R语言绘图(2)-均值误差折线图

所用R包: tidyverse

1.所需数据计算

#数据转置
adam1 <- adam %>% pivot_longer(variables,names_to="Time",values_to="ADL")
#计算ADL的标准误
tgc1 <- summarySE(adam1, measurevar="ADL", groupvars=c("分组","Time"),na.rm=T)
#组间差异检验
t.test(adam$ADL基线总分0,by="分组")
#或使用gtsummay包批量检验

2.绘图

P1 <- ggplot(tgc1, aes(x = Time, y = ADL, colour = 分组, group = 分组)) +   
  geom_errorbar(aes(ymin = ADL - se, ymax = ADL + se), width = 0.1) + #添加误差区间
  geom_line() +
  geom_point(shape = 16, size = 3) +  # Use shape = 17 for triangles and adjust size
  annotate(geom="text",x=5,y=-5.9,label="*")+ #在有差异的时点添加标识符
  theme_bw() +
  labs(
    x = "Week",                # Set the x-axis label
    y = "ADL Score",           # Set the y-axis label
    colour = "Group"           # Set the legend title
  ) +
  geom_hline(yintercept = 0, linetype = "dashed", colour = "black")+ #添加水平虚线
  scale_colour_manual(
    values = c("red", "blue"),           # Define custom colours for groups
    labels = c("组1", "组2")              # Set the labels for groups
  ) +
  
  theme(
    legend.position = "top",   # Position the legend at the top
    legend.title = element_text(size = 12),  # Adjust legend title font size
    legend.text = element_text(size = 10),   # Adjust legend text size
    axis.title = element_text(size = 14),    # Adjust axis title font size
    axis.text = element_text(size = 12)      # Adjust axis text font size
  )
P1

3.数据及图形示例

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇