其他
让ggplot2变成Graphpad Prism样式:ggprism(01)
简介
ggprism
是ggplot2
的扩展包,可以让你的图形看起来像GraphPad Prism形式。使用起来非常简单,一行代码即可!支持目前Graphpad Prism的所有主题!
安装
install.packages("ggprism")
# 或使用github版
remotes::install_github("csdaw/ggprism")
主题
theme_prism()
是使用最多的函数,可以让你的图形看起来像GraphPad Prims画出来的。
使用主题
默认图形:
library(ggplot2)
library(ggprism)
library(patchwork)
base <- ggplot(mpg, aes(x = displ, y = cty)) +
geom_point(aes(colour = class))
base
theme_prism()
主要通过改变以下元素使得图形看起来像GraphPad Prism风格:
改变字体粗细和大小 改变背景颜色 隐藏图例标题
# 使用主题
p1 <- base + theme_prism() +
theme(legend.position = c(0.8,0.75),
legend.key.height = unit(10,"pt"))
p2 <- base + theme_prism() +
theme(legend.position = c(0.8,0.75),
legend.key.height = unit(10,"pt"),
legend.title = element_text())
p1 + p2
改变字体大小:
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
改变坐标轴粗细:
p1 <- base + theme_prism(base_size = 14)
p2 <- base + theme_prism(base_size = 14, base_line_size = 0.2)
p1 + p2
改变字体:
p1 <- base + theme_prism(base_fontface = "plain")
p2 <- base + theme_prism(base_family = "mono")
p1 + p2
改变横坐标标签方向:
p1 <- base + theme_prism(axis_text_angle = 45)
p2 <- base + theme_prism(axis_text_angle = 90)
p1 + p2
增加边框:
p1 <- base + theme_prism(border = TRUE) +
coord_cartesian(clip = "off") # 必须加这个函数
p2 <- base + theme_prism(border = TRUE, base_rect_size = 2) + # adjust thickness
coord_cartesian(clip = "off")
p1 + p2
查看所有主题
names(ggprism_data$themes)
## [1] "autumn_leaves" "beer_and_ales" "black_and_white" "candy_bright"
## [5] "candy_soft" "colorblind_safe" "colors" "diazo"
## [9] "earth_tones" "evergreen" "greenwash" "muted_rainbow"
## [13] "office" "purple_passion" "shades_of_gray" "summer"
## [17] "the_blues" "winter_soft" "stained_glass" "warm_pastels"
## [21] "flames" "floral" "inferno" "magma"
## [25] "mustard_field" "neon" "pastels" "pearl"
## [29] "plasma" "prism_dark" "prism_light" "quiet"
## [33] "spring" "starry" "viridis" "waves"
## [37] "blueprint" "fir" "ocean" "sunny_garden"
## [41] "wool_muffler" "warm_and_sunny" "winter_bright" "all_null"
一共这么多主题,基本上常见的GraphPad Prism主题都有了!
使用几个试试看:
p1 <- base + theme_prism(palette = "purple_passion")
p2 <- base + theme_prism(palette = "candy_bright")
p1 + p2
可以使用preview_theme()
预览主题:
preview_theme("flames")
还提供了scale_fill_prism
和scale_color_prism
函数,建议和theme_prism
一起使用时,使用相同的主题:
p1 <- base + theme_prism(palette = "summer") + scale_color_prism(palette = "summer")
p2 <- base + theme_prism(palette = "stained_glass") + scale_color_prism(palette = "stained_glass")
p1 + p2
制作自己的主题
GraphPad Prism的大多数主题都很丑不适合发表,你也可以制作自己的主题。
theme_new <- function(base_size = 14,
base_family = "sans",
base_fontface = "bold",
base_line_size = base_size / 14,
base_rect_size = base_size / 14,
axis_text_angle = 0,
border = FALSE) {
theme_prism(palette = "stained_glass",
base_size = base_size,
base_family = base_family,
base_fontface = base_fontface,
base_line_size = base_line_size,
base_rect_size = base_rect_size,
axis_text_angle = axis_text_angle,
border = border) %+replace%
theme(panel.background = element_rect(fill = "white",
colour = NA),
plot.background = element_rect(fill = "red",
colour = NA),
axis.line = element_line(colour = "black"),
axis.ticks = element_line(colour = "black"))
}
base + theme_new()
以上就是今天的内容,希望对你有帮助哦!欢迎点赞、在看、关注、转发!
欢迎在评论区留言或直接添加我的微信!
欢迎关注我的公众号:医学和生信笔记
“医学和生信笔记 公众号主要分享:1.医学小知识、肛肠科小知识;2.R语言和Python相关的数据分析、可视化、机器学习等;3.生物信息学学习资料和自己的学习笔记!
往期精彩内容:
R语言生信图表学习之网络图
R语言ggplot2画相关性热图
R语言可视化聚类树