#### 七、图片拼接 ####
#install.packages("ggprism") ##https://zhuanlan.zhihu.com/p/557138945
library(ggplot2)
library(ggprism)
library(reshape)
library(ggpubr)
# 7.1 fig.1(改成分类变量)
p1 <- ggplot(newdata,aes(x=edugroup,y=a15,fill=edugroup))+
geom_boxplot(width=0.6,alpha=0.8)
p1
# 7.2 fig.3(改成分类变量)
p3<-ggplot(newdata, aes(x = edugroup, y=a15,fill=edugroup))+
geom_violin(trim = T,position = position_dodge(width = 0.1))+
geom_boxplot(alpha=1,outlier.size=0, size=0.3, width=0.2,fill="white")+
stat_summary(fun="mean",geom="point",shape=21, size=2,fill="blue")+
labs(x="Samples",y=NULL)+
theme_prism(palette = "flames",
base_fontface = "plain",
base_family = "serif",
base_size = 16,
base_line_size = 0.8,
axis_text_angle = 45)+
scale_fill_prism(palette = "candy_bright")+
theme(legend.position = 'none')
p3
##7.3 cowplot包实现多子图拼接
cowplot::plot_grid(p1,p3,ncol = 2)#按照两行排列
##异质性绘图
###A.可以分组+ by = "sex",
p1 <- visreg(hefit003, "b310b_18", line = list(col = "red"),
fill = list(fill = "orange"), points = list(size = 3, pch = 21),
gg = TRUE,
scale="response") +
labs(y = " Cognitive Impairment",
x = "Sleep Duration (h)",
title = "Relationship of sleep duration and cognitive impairment",
subtitle = "controlling for covariate")
p1
p2 <- visreg(hefit004, "b310b_18", line = list(col = "red"),
fill = list(fill = "orange"), points = list(size = 3, pch = 21),
gg = TRUE,
scale="response") +
labs(y = " Cognitive Impairment",
x = "Sleep Duration (h)",
title = "Relationship of sleep duration and cognitive impairment",
subtitle = "controlling for covariate")
p2
## B.cowplot包实现多子图拼接
cowplot::plot_grid(p1,p2,ncol = 2)#按照两行排列
##C.组合绘图(自带函数)
visreg(lofit01, "b310b_18", by = "sexgroup")
图形拼接r
于 2022-09-21 08:24:27 首次发布