跳转至

转载自Y叔的公众号,侵权立删。

remotes::install_github("csdaw/ggprism")
library(ggplot2) #作图
library(ggprism) #可以完善ggplot2的图使之达到发表级别
library(patchwork) #用来拼图

左侧为原始图,右侧为使用ggprism主题后

调整字体大小和坐标轴粗细

p1 <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) + 
  stat_summary(aes(fill = factor(dose)), na.rm = TRUE,
               geom = "col", fun = mean, colour = "black", size = 0.9) + 
  scale_y_continuous(limits = c(0, 30), expand = c(0, 0))+theme_classic()
p2 <- p1 + theme_prism(base_size = 13)
p1 + p2

加粗坐标轴和文字

调整图和图例的颜色

p <- ggplot(ToothGrowth, aes(x = factor(supp), y = len)) + 
  geom_boxplot(aes(colour = factor(supp), fill = factor(supp))) + 
  theme_prism(base_size = 14)

p1 <- p + scale_colour_prism(palette = "floral") + 
  scale_fill_prism(palette = "floral")

p2 <- p + scale_colour_prism(palette = "flames") + 
  scale_fill_prism(palette = "flames")

p+p1 + p2

不同的配色方案

调整坐标轴

p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) + 
  geom_jitter(aes(shape = factor(dose)), width = 0.2, size = 2) + 
  scale_shape_prism() + 
  theme_prism() + 
  theme(legend.position = "none")

p1 <- p + scale_y_continuous(limits = c(0, 40), guide = "prism_minor")

p2 <- p + scale_x_discrete(guide = "prism_bracket") + #使x坐标轴分段
  scale_y_continuous(limits = c(0, 40)) 

p3 <- p + scale_y_continuous(limits = c(0, 40), guide = "prism_offset") #y轴与x轴分离

p4 <- p + scale_y_continuous(limits = c(0, 40), guide = "prism_offset_minor")

(p1 + p2) / (p3 + p4)

调整坐标轴

添加p值

#创建数据框,指定分组信息、p值、p值在y轴的位置
df_p_val <- data.frame(
  group1 = "OJ",
  group2 = "VC",
  p.adj = 0.0606,
  y.position = 36
)

# make a plot
p1 <- ggplot(ToothGrowth, aes(x = factor(supp), y = len)) + 
  geom_boxplot(aes(fill = factor(supp))) + 
  scale_fill_prism(palette = "candy_bright") + 
  theme_prism() + 
  theme(legend.position = "none")

# add the p-value
p2 <- p1 + add_pvalue(df_p_val)

p1 + p2

image.png

回到页面顶部