首页 > 其他分享 >R语言,dotplot的使用

R语言,dotplot的使用

时间:2023-04-28 11:58:59浏览次数:27  
标签:dodge 语言 color geom 使用 fun position data dotplot

一步步绘制和美化dot plot
简介
开始
1. 查看数据并转换为长数据格式
2. 绘制基础图形
3. 添加errorbar和pointrange
4. 修改颜色和坐标轴主题
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")

 


总结
绘图时要思路清楚,一步一步实现。勤加练习!
————————————————
版权声明:本文为CSDN博主「生信小菜鸟啊」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40794743/article/details/113989344

标签:dodge,语言,color,geom,使用,fun,position,data,dotplot
From: https://www.cnblogs.com/ranXU/p/17361680.html

相关文章

  • xlwings 使用手册
    前言本人目前也在学习中,仍有不足或考虑不全面的地方.如若发现文档内容存在错误请联系我更改.谢谢!pip国内源清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/阿里云:http://mirrors.aliyun.com/pypi/simple/中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/华......
  • java 语言与 C语言端 AES (ECB)
    注:java为no-padding注释掉了padding部分(byte数组初始化时为0x00)c为padding0x00(byte数组初始化时为0x00)代码出自网上代码地址githubhttps://github.com/mountwater/AES-128-ECB-java_and_cJAVA代码//CopyrightPopaTiberiu2011//f......
  • 使用jquery探测移动设备 How to detect mobile devices using jQuery
     Helloeveryone,yesterdayIreceivedarequestfromtheclient.HewantedtodisablethepopupofNewsletterPopupextensionwhencustomersvisithiswebsiteonmobiledevices.ItgavemeachancetoworkwithjQueryagainandfinallyIcameupwitha......
  • 使用Mockito-mock,void方法
    示例publicResponsedate(Stringurl){@ResourceprivateIRuleJudgmentServiceruleJudgmentService;//示例方法,伪代码ruleJudgmentService.ruleJudgement(参数,参数);//其他业务returnResponse;}调用的void方法publicinterfa......
  • 如何使用CSS来修改SVG原点和制作SVG动画
    SVG元素可以像HTML元素一样,使用CSSkeyframes和animation属性或者CSStransitions来制作各种动画效果。 SVG元素可以像HTML元素一样,使用CSSkeyframes和animation属性或者CSStransitions来制作各种动画效果。大多数情况下,一个复杂的动画效果需要组合多种变换效果:旋转、倾......
  • 使用Solrj管理Solr索引
    Solrj是Solr搜索服务器的一个比较基础的客户端工具,可以非常方便地与Solr搜索服务器进行交互,最基本的功能就是管理Solr索引,包括添加、更新、删除和查询等。对于一些比较基础的应用,用Solj基本够用,而且你可以非常容易地通过使用Solrj的API实现与Solr搜索服务器进行交互,实现对Solr的基......
  • 高性能序列化、反序列化protostuff 使用
    1、引用jar包:pom.xml:<!--protostuff--><dependency><groupId>com.dyuproject.protostuff</groupId><artifactId>protostuff-core</artifactId><version>1.0.7</version>......
  • 【HarmonyOS】元服务WebView组件 H5使用localstorage
    在日常开发中我们会在应用种接入H5网页,localStorage作为H5本地存储webstorage特性的API之一,主要作用是将数据保存在客户端中。对于快速开发元服务,通过WebView组件运行H5如何使用localstorage呢?下文以API7JavaUI为例为大家做相关的讲解。 【实现步骤】第一步、配置WebView首......
  • 【远程连接工具】xshell上用vi/vim小键盘无法使用的修改办法
    转至:https://blog.csdn.net/qq_44676946/article/details/117257410问题:后台开发人员经常使用Xshell来访问远程服务器,在用vim(或vi)编辑文件的时,使用小键盘数字键的时候,可能会输入一堆字母和换行,并不是数字。修改:1.修改会话属性2.选择类别“终端”-VT模式3.选择“初始数字键盘......
  • c语言中,字符数组名 与 指向字符串常量的指针之间的关系
    chara[]="hello";//定义一个字符数组a,constchar*b="hello";//定义一个指向字符的指针b,指向字符串常量的第一个字符的首地址区别:a是一个指针常量,它本身的值不能修改,即char*consta;b是一个常量指针,它所指向的值不能修改,constchar*b;......