R语言基础绘图 您所在的位置:网站首页 r语言添加网格线 R语言基础绘图

R语言基础绘图

2023-09-08 00:27| 来源: 网络整理| 查看: 265

一步步绘制和美化dot plot 简介开始1. 查看数据并转换为长数据格式2. 绘制基础图形3. 添加errorbar和pointrange4. 修改颜色和坐标轴主题5. 加注释 总结

简介

作为文章中经常出现的一种图形,dot plot 可以展示点的分布和统计变化之后的数据均值等特征值。以下是一篇已发表的文章中的图,今天我们将构造数据,一步步实现它。 在这里插入图片描述

开始 1. 查看数据并转换为长数据格式

在这里插入图片描述 在这里插入图片描述

library(tidyverse) library(magrittr) data %% pivot_longer(cols = wt:mz_ko)

在这里插入图片描述

2. 绘制基础图形 data %>% ggplot(aes(group, value, fill = name)) + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.9))

在这里插入图片描述

3. 添加errorbar和pointrange data %>% ggplot(aes(group, value, fill = name)) + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.9)) + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="errorbar", color="black", width = .07, position = position_dodge(.9), size = .8)

在这里插入图片描述

data %>% ggplot(aes(group, value, fill = name)) + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.9)) + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="errorbar", color="black", width = .07, position = position_dodge(.9), size = .8) + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="pointrange", color="black", position = position_dodge(.9))

在这里插入图片描述 有点感觉了哦!

4. 修改颜色和坐标轴主题 data %>% ggplot(aes(group, value, fill = name)) + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.9), color = "grey77") + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="errorbar", color="black", width = .07, position = position_dodge(.9), size = .8) + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="pointrange", color="black", position = position_dodge(.9)) + scale_y_continuous(limits = c(0, 1.5), expand = c(0, 0)) + scale_fill_manual(values = c("grey77", "grey77")) + labs(x= "", y = "Relative itensity") + theme_classic() + theme(axis.ticks.x = element_blank(), axis.text.x = element_blank(), legend.position = "none")

在这里插入图片描述 最后,再加上注释就可以了,来实现吧。

5. 加注释

加线段和文本建议使用AI,当然也可以用R实现。

data %>% ggplot(aes(group, value, fill = name)) + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.9), color = "grey77") + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="errorbar", color="black", width = .07, position = position_dodge(.9), size = .8) + stat_summary(fun.data=mean_sdl, fun.args = list(mult=1), geom="pointrange", color="black", position = position_dodge(.9)) + geom_segment(aes(x = 0.5, y = 1.37, xend = 1.5, yend = 1.37), color = "black", size = .5) + geom_segment(aes(x = 1.6, y = 1.37, xend = 2.3, yend = 1.37), color = "black", size = .5) + annotate(geom = "text", x = c(0.95, 1.95), y = 1.47, label = c("Early 2-cell", "Late 2-cell")) + annotate(geom= "text", x = c(0.77, 1.2, 1.75, 2.22), y = 1.3, label = c(rep(c("WT", "MZ-KO"),2))) + scale_y_continuous(limits = c(0, 1.5), expand = c(0, 0)) + scale_fill_manual(values = c("grey77", "grey77")) + labs(x= "", y = "Relative itensity") + theme_classic() + theme(axis.ticks.x = element_blank(), axis.text.x = element_blank(), legend.position = "none")

在这里插入图片描述

总结

绘图时要思路清楚,一步一步实现。勤加练习!

欢迎关注我的微信公众号。 在这里插入图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有