美文网首页基因组数据绘图ggplot2绘图
ggprism包数据可视化之主题设置

ggprism包数据可视化之主题设置

作者: R语言数据分析指南 | 来源:发表于2021-02-18 20:35 被阅读0次

ggprism软件包提供了各种主题自定义ggplot2并赋予它们“ GraphPad Prism”外观,喜欢的小伙伴可以关注个人公众号R语言数据分析指南持续分享更多优质资源,在此先行拜谢了!!

install

install.packages("ggprism")

安装开发版

remotes::install_github("csdaw/ggprism")

使用案例1.

library(ggprism)
library(tidyverse)
library(patchwork)

tg <- ToothGrowth
tg$dose <- as.factor(tg$dose)

base <- ggplot(tg, aes(x = dose, y = len)) + 
  geom_violin(aes(colour = dose, fill = dose),trim = FALSE) + 
  geom_boxplot(aes(fill = dose),width = 0.2, colour = "black") + 
  scale_y_continuous(limits = c(-5, 40))

p_vals <- tibble::tribble(
  ~group1, ~group2, ~p.adj,   ~y.position,
  "0.5",   "1",     8.80e-14, 35,
  "0.5",   "2",     1.27e-7,  39
)

base

p <- base + 
  scale_color_prism("floral") + 
  scale_fill_prism("floral") + 
  guides(y = "prism_offset_minor") + 
  theme_prism(base_size = 5) + 
  theme(legend.position = "none") + 
  add_pvalue(p_vals, label = "p = {p.adj}",
             tip.length = 0, label.size = 2)
base+p

主题设置

theme_prism()`可以说是该程序包中最有用的部分。它是用来使ggplots看起来像在GraphPad Prism中制作的主要工具

整个主题文本的大小可以通过base_size参数进行调整

base <- ggplot(mpg, aes(x = displ, y = cty)) +
  geom_point(aes(colour = class), show.legend = FALSE)

p1 <- base + theme_prism(base_size = 10)
p2 <- base + theme_prism(base_size = 16)

p1 + p2

base_line_size设置线条粗细

p1 <- base + theme_prism(base_size = 14)
p2 <- base + theme_prism(base_size = 14, base_line_size = 0.2)

p1 + p2

base_fontface修改字体 (例如,粗体,普通,斜体) 和base_family (使用跨平台兼容字体例如衬线,sans,mono或特定字体,例如Arial)

p1 <- base + theme_prism(base_fontface = "plain")
p2 <- base + theme_prism(base_family = "mono")

p1 + p2

axis_text_angle修改文本角度(允许的角度为:0、45、90或270)

p1 <- base + theme_prism(axis_text_angle = 45)
p2 <- base + theme_prism(axis_text_angle = 90)

p1 + p2

border添加边框

p1 <- base + theme_prism(border = TRUE) + 
  coord_cartesian(clip = "off")
p2 <- base + theme_prism(border = TRUE, base_rect_size = 2) +
  coord_cartesian(clip = "off")

p1 + p2

主题调色板

内置了几种不同的调色板theme_prism()

> names(ggprism_data$themes)
 [1] "autumn_leaves"   "beer_and_ales"   "black_and_white" "candy_bright"    "candy_soft"     
 [6] "colorblind_safe" "colors"          "diazo"           "earth_tones"     "evergreen"      
[11] "greenwash"       "muted_rainbow"   "office"          "purple_passion"  "shades_of_gray" 
[16] "summer"          "the_blues"       "winter_soft"     "stained_glass"   "warm_pastels"   
[21] "flames"          "floral"          "inferno"         "magma"           "mustard_field"  
[26] "neon"            "pastels"         "pearl"           "plasma"          "prism_dark"     
[31] "prism_light"     "quiet"           "spring"          "starry"          "viridis"        
[36] "waves"           "blueprint"       "fir"             "ocean"           "sunny_garden"   
[41] "wool_muffler"    "warm_and_sunny"  "winter_bright"   "all_null"   

切换调色板

p1 <- base + theme_prism(palette = "purple_passion")
p2 <- base + theme_prism(palette = "candy_bright")

p1 + p2

原文链接:https://mp.weixin.qq.com/s/ik01O0V-qvvNDhlNYaUGZQ

相关文章

网友评论

    本文标题:ggprism包数据可视化之主题设置

    本文链接:https://www.haomeiwen.com/subject/aqpnxltx.html