1.先画雏形
library(ggplot2)
ggplot(data = iris,aes(Sepal.Width,Species))+
geom_violin()+
geom_boxplot()+
geom_jitter()
#图层的叠放顺序由什么决定
#先写的先放
2.设置背景颜色
ggplot(data = iris,aes(Sepal.Width,Species))+
geom_violin(aes(fill = Species))+
geom_boxplot()+
geom_jitter(aes(shape = Species))+
theme_classic()
运行一下以上代码,看看画出来的图是不是一模一样!
sample(letters,3)
## [1] "i" "s" "w"
sample(letters,27,replace = T)
## [1] "p" "n" "g" "s" "r" "e" "z" "c" "t" "h" "g" "w" "w" "f"
## [15] "q" "a" "m" "i" "u" "w" "n" "l" "f" "h" "x" "d" "s"
set.seed(5)#设置随机种子,保证每一次都取这些数
sample(letters,3)
## [1] "b" "k" "o"
m = c("xiaoli","xiaole","xiaofang",letters)
set.seed(18780)
sample(m,10)
## [1] "w" "d" "r" "k" "v" "xiaoli"
## [7] "s" "t" "x" "o"
m2 = c(paste0("入门",1:6),paste0("挖掘",1:3))
m2
## [1] "入门1" "入门2" "入门3" "入门4" "入门5" "入门6" "挖掘1"
## [8] "挖掘2" "挖掘3"
set.seed(10086)
sample(m2,1)
## [1] "入门2"
set.seed(19875)
sample(m2,1)
## [1] "入门1"
set.seed(1710165991)
sample(m2,1)
## [1] "挖掘3"
# ggpubr 搜代码直接用,基本不需要系统学习
# sthda上有大量ggpubr出的图
library(ggpubr)
p = ggboxplot(iris, x = "Species", y = "Sepal.Length",
color = "Species", shape = "Species",add = "jitter")
p
my_comparisons <- list( c("setosa", "versicolor"),
c("setosa", "virginica"),
c("versicolor", "virginica") )
p + stat_compare_means(comparisons = my_comparisons,
aes(label = after_stat(p.signif)))
pdf("iris_box_ggpubr.pdf") #图的文件名称有意义
boxplot(iris[,1]~iris[,5])
text(6.5,4, labels = 'hello')
dev.off() #关闭画板#可多次运行到null device为止或dev.new()
## RStudioGD
## 2
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
ggsave(p,filename = "iris_box_ggpubr.png")
library(eoffice)
topptx(p,"iris_box_ggpubr.pptx")#超多点和超多行列不行,ppt会卡掉
#https://mp.weixin.qq.com/s/p7LLLvzR5LPgHhuRGhYQBQ
引用自生信技能树课程
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。