特点:
ggscatter(iris,x="Sepal.Length",y="Petal.Length",color="Species")
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)+ # Add pairwise comparisons p-value
stat_compare_means(label.y = 9)
图片保存的三种办法
1.基础包作图的保存
pdf("iris_box_ggpubr.pdf")
boxplot(iris[,1]~iris[,5])
text(6.5,4, labels = 'hello')
dev.off()
2.ggplot系列图(包括ggpubr)通用的简便保存 ggsave
p <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
ggsave(p,"iris_box_ggpubr.png")
3.eoffice包 导出为ppt,全部元素都是可编辑模式
library(eoffice)
topptx(p,"iris_box_ggpubr.pptx")
图片拼图patchwork包
1. 拼图
P1+P2
2. 统一修改主题
加上P1+P2&theme_bw()
3. 收集图例
加上+plot_layout(guides="collect")
4. 修改布局P1/P2
5. 加ABCE
+plot
用法
library(patchwork)
p1 = ggscatter(iris,x="Sepal.Length",
y="Petal.Length",
color="Species")
p2 <- ggboxplot(iris, x = "Species",
y = "Sepal.Length",
color = "Species",
shape = "Species",
add = "jitter")
p3 = ggplot(data = mpg, mapping = aes(x = class, y = hwy)) +
geom_boxplot()
p4 = ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = cut),
show.legend = FALSE,
width = 1
)
p1 + p2 + p3 + p4 + plot_annotation(tag_level = "A")
p1/p2
- 代码运行却不出图:画板被占用
dev.off()
或者
dev.new()
网友评论