# R绘图笔记 | 散点分布图与柱形分布图

https://docs.qq.com/sheet/DV0dxREV1YkJ0ZmVj

```library(ggplot2)
library(RColorBrewer)
library(SuppDists) #提供rJohnson()函数
library(ggbeeswarm)```
`data <- read.csv("BioInfoNotesData1.csv",row.names = 1)`

```f1.data <- data[,c(1,5)]
colnames(f1.data) <- c("Stage","Value")
summary(f1.data\$Stage)```
```summary(f1.data\$Stage)
N   Stage I  Stage II Stage III  Stage IV
11        75       176       128        64```

```f1.data<-f1.data[f1.data\$Stage!="N",]
```BioinfoNotes>head(f1.data)
Stage Value
TCGA-3L-AA1B-01   Stage I  7.04
TCGA-4N-A93T-01 Stage III  7.23
TCGA-4T-AA8H-01  Stage II  6.61
TCGA-5M-AAT4-01  Stage IV  7.56
TCGA-5M-AAT6-01  Stage IV  4.99
TCGA-5M-AATE-01  Stage II  7.41```

1.散点抖动图

```ggplot(f1.data, aes(Stage, Value))+
geom_jitter(aes(fill = Stage),position = position_jitter(0.3),shape=21, size = 2)+
scale_fill_manual(values=c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+
theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)```

2.蜂群图

```#蜂群图
ggplot(f1.data, aes(Stage, Value))+
geom_beeswarm(aes(fill = Stage),shape=21,colour="black",size=2,cex=2)+
scale_fill_manual(values= c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+
xlab("Stage")+
ylab("Value")+
theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)```

3.点阵图

```ggplot(f1.data, aes(Stage, Value))+
geom_dotplot(aes(fill = Stage),binaxis='y', stackdir='center', dotsize = 0.6)+
scale_fill_manual(values=c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+
theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)
```

4.带误差线的散点分布图

```ggplot(f1.data, aes(Stage, Value))+
geom_jitter(aes(fill = Stage),position = position_jitter(0.3),shape=21, size = 2,color="black")+

scale_fill_manual(values=c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+

stat_summary(fun.data="mean_sdl", fun.args = list(mult=1),
geom="pointrange", color = "black",size = 1.2)+
stat_summary(fun.y="mean", fun.args = list(mult=1),
geom="point", color = "white",size = 4)+

theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)```

5.带误差线的柱形分布图

```ggplot(f1.data, aes(Stage, Value))+
stat_summary(mapping=aes(fill = Stage),fun.y=mean, fun.args = list(mult=1),geom='bar',colour="black",width=.7) +
stat_summary(fun.data = mean_sdl, fun.args = list(mult=1),geom='errorbar', color='black',width=.2) +
scale_fill_manual(values=c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+
ylim(0,7.5)+
theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)```

6.带误差线柱形与抖动图

```ggplot(f1.data, aes(Stage, Value))+
stat_summary(fun.y=mean, fun.args = list(mult=1),geom='bar',colour="black",fill="white",width=.7) +
stat_summary(fun.data = mean_sdl,fun.args = list(mult=1), geom='errorbar', color='black',width=.2) +
geom_jitter(aes(fill = Stage),position = position_jitter(0.2),shape=21, size = 2,alpha=0.9)+
scale_fill_manual(values=c(brewer.pal(7,"Set2")[c(1,2,4,5)]))+
theme_classic()+
theme(panel.background=element_rect(fill="white",colour="black",size=0.25),
axis.line=element_line(colour="black",size=0.25),
axis.title=element_text(size=13,face="plain",color="black"),
axis.text = element_text(size=12,face="plain",color="black"),
legend.position="none"
)```

1.R语言数据可视化之美，张杰/著

0 条评论

• ### R绘图笔记 | 柱状图绘制

绘图：geom_bar用于绘制柱状图，ylim设置纵轴值范围，them设置主题，axis.title设置坐标轴名称参数，axis.text设置坐标轴参数。

• ### R绘图笔记 | 一般的散点图绘制

plot函数中，x和y分别表示所绘图形的横坐标和纵坐标；函数中的...为附加的参数。plot函数默认的使用格式如下：

• ### 测试开发进阶(十五)

现在做成，成功且状态码正确弹框提示「登录成功」，成功但状态码错误弹框提示「登录失败」，ajax发送失败提示「请求失败」

• ### HTML5 自定义属性 data-* 和 jQuery.data 详解

新的HTML5标准允许你在普通的元素标签里，嵌入类似data-*的属性，来实现一些简单数据的存取。它的数量不受限制，并且也能由javascript动态修改，也支...

• ### 行业 | 2018年，哪些行业在悄然进行数字化转型？

经历了2017年的快速升温，2018年电子合同市场发展可以用一个词来形容“迅猛”！在这一年，除了技术与用户习惯日趋成熟等因素外，《电子商务法》的出台，房地产行业...

• ### 爬虫学习(二)

To understand and be understood, those are among life’s greatest gifts, and ever...

• ### 数说成龙电影|数据告诉你，成龙大哥真的老了吗

最近的电影《哪吒》绝对是风靡全国，各种“我命由我不由天”，激励着平民大众。而《上海堡垒》则彻底扑街，鹿晗也跌落神坛，流量不再。而老大哥成龙的新片《龙牌之谜》也在...

• ### django rest framework serializers解读

serializers.fieild 我们知道在django中，form也有许多field，那serializers其实也是drf中发挥着这样的功能。我们...

,,