R语言作图实战——barplot

作者: 克里克的钟 | 来源:发表于2019-10-10 22:26 被阅读0次

图片来源于新英格兰医学杂志文章:https://www.nejm.org/doi/full/10.1056/NEJMoa1715944

Ref: Witztum, J. L., Gaudet, D., Freedman, S. D., Alexander, V. J., Digenio, A., Williams, K. R., … Bruckert, E. (2019). Volanesorsen and Triglyceride Levels in Familial Chylomicronemia Syndrome. New England Journal of Medicine, 381(6), 531–542.

image

Placebo相对于baseline增加了18%,而Volanesorsen组相对于baseline减少了77%。

代码:


group <- rep(c('placebo', 'Volanesorsen'),each = 10)
set.seed(1)
placebo <- rnorm(10, mean = 18, sd = 22)
set.seed(2)
Volanesorsen <- rnorm(10, mean = -77, sd = 14)
data <- data.frame(group, value = append(placebo, Volanesorsen))
table <- data %>%
  group_by(group) %>%
  summarize(
    Mean = mean(value),
    sd = sd(value)
  )
x = ggplot() +
  geom_bar(table,
          mapping = aes(x = group, y = Mean),
          fill = c('darkred','gray'),
          stat="identity",
          width = 0.4) +
  geom_errorbar(table, mapping = aes(x = group, ymin=Mean-sd, ymax=Mean+sd),
                width=.05,
                size = 0.25,# 设置误差线的宽度
                position=position_dodge(.9))+
  geom_text(table, mapping = aes(x = "placebo", y = 40, label = 18), size = 3)+
  geom_text(table, mapping = aes(x = "Volanesorsen", y = -100, label = -77), size = 3)+
  scale_y_continuous(breaks = seq(-110,60, by = 20))+
  labs(
    x = "",
    y = "percentage change from baseline"
  )+
  theme_classic()
y = x +geom_hline(yintercept = 0, linetype =3, color = 'grey') +
  theme(axis.line = element_line(size=0.4, colour = 'grey'),
  axis.text=element_text(size=8,colour="black"))
tiff("fig.tiff", res = 300, width = 800, height = 1200)
y
dev.off()

结果如图:


image.png

相关文章

  • R语言作图实战——barplot

    图片来源于新英格兰医学杂志文章:https://www.nejm.org/doi/full/10.1056/NEJ...

  • R语言作图实战——boxplot

    一、基础知识 箱式图用于多组数据平均水平和变异程度的直观分析比较。每一组数据均可呈现其最小值(Minimum)、Q...

  • Barplot 作图代码

    ggplot2 barplot 分面图代码如下: 数据源(data.txt):

  • 学习小组Day4笔记-皇晓燕

    R语言和R studio R语言是全面的统计分析平台,计算作图等等 R studio是R语言的操作平台 下载R语言...

  • R语言|绘制环状的堆叠条形图

    堆叠条形图的进阶版,极坐标下的barplot,下面是R绘制堆叠的环状条形图的小例子。 关注“作图帮”公众号免费分享...

  • 学习小组day4笔记-曾俊辉

    R语言和R studio R语言是全面的统计分析平台,计算作图等等等等R studio是R语言的操作平台 下载R语...

  • R语言 条形图

    条形图表示矩形条中的数据,条的长度与变量的值成比例。 R语言使用函数barplot()创建条形图。 R语言可以在条...

  • 03-08

    06 R语言作图 图就是数据,数据就是图 常用可视化R包 作图:base,ggplot2, ggpubr;拼图:p...

  • R语言 循环作图

  • R语言作图基础

    本文非原创 par()函数的参数可见:R 绘图参数设置函数par()详解 文字 点、线 点和线是很基础的元素,点的...

网友评论

    本文标题:R语言作图实战——barplot

    本文链接:https://www.haomeiwen.com/subject/iwlzpctx.html