查看原文
其他

让ggplot2变成Graphpad Prism样式:ggprism(02)

阿越就是我 医学和生信笔记 2023-02-25

简介

ggprismggplot2的扩展包,可以让你的图形看起来像GraphPad Prism形式。使用起来非常简单,一行代码即可!支持目前Graphpad Prism的所有主题!

前面介绍了theme_prism,接下来介绍color/fill/shape

安装

install.packages("ggprism")

# 或使用github版
remotes::install_github("csdaw/ggprism")

color、fill、shape

提供GraphPad Prism里面常见的颜色组合,基本上都是色盲友好型,可以放心使用。

color

首先创建一个基本图形:

library(ggplot2)
library(ggprism)


base <- ggplot(mtcars, aes(wt, mpg)) + geom_point(aes(color = factor(cyl), shape = factor(cyl)), size = 3) + 
  theme_prism() + theme(legend.position = c(0.8,0.8))

base

查看所有颜色组合:

lengths(ggprism_data$colour_palettes)
##   autumn_leaves   beer_and_ales black_and_white       blueprint      blueprint2 
##               9               9               9               9               9 
##      blueprint3    candy_bright      candy_soft colorblind_safe          colors 
##               9               9               9               6              20 
##           diazo     earth_tones       evergreen             fir            fir2 
##               9              10               9               9               9 
##            fir3          flames         flames2          floral         floral2 
##               9               9               9              12              12 
##       greenwash         inferno           magma   mustard_field  mustard_field2 
##              10               6               6               9               9 
##   muted_rainbow            neon           ocean          ocean2          ocean3 
##              10               9               9               9               9 
##          office         pastels           pearl          pearl2          plasma 
##               9               9               6               6               6 
##      prism_dark     prism_dark2     prism_light    prism_light2  purple_passion 
##              10              10              10              10               9 
##           quiet          quiet2  shades_of_gray          spring         spring2 
##               9               9               9               9               9 
##   stained_glass  stained_glass2          starry         starry2          summer 
##               9               9               5               5              10 
##    sunny_garden   sunny_garden2   sunny_garden3       the_blues         viridis 
##               9               9               9               9               6 
##  warm_and_sunny    warm_pastels   warm_pastels2           waves          waves2 
##               9               9               9               5               5 
##   winter_bright     winter_soft    wool_muffler   wool_muffler2   wool_muffler3 
##               9               9               9               9               9

随便使用几个主题试试:

p1 <- base + scale_color_prism(palette = "autumn_leaves")
p2 <- base + scale_color_prism(palette = "ocean")
p3 <- base + scale_color_prism()

p1 + p2 + p3

fill

先创建一个基本图:

base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(aes(fill = factor(cyl), shape = factor(cyl)), size = 3) + 
  theme_prism() + 
  theme(legend.position = c(0.80.8)) + 
  scale_shape_prism(palette = "filled")

base

查看所有颜色组合:

lengths(ggprism_data$fill_palettes)
##   autumn_leaves   beer_and_ales black_and_white       blueprint    candy_bright 
##               9               9               9               9               9 
##      candy_soft colorblind_safe          colors           diazo     earth_tones 
##               9               6              20               9              10 
##       evergreen             fir          flames          floral       greenwash 
##               9               9               9              12              10 
##         inferno           magma   mustard_field   muted_rainbow            neon 
##               6               6               9              10               9 
##           ocean          office         pastels           pearl          plasma 
##               9               9               9               6               6 
##      prism_dark     prism_light  purple_passion           quiet  shades_of_gray 
##              10              10               9               9               9 
##          spring   stained_glass          starry          summer    sunny_garden 
##               9               9               5              10               9 
##       the_blues         viridis  warm_and_sunny warm_and_sunny2    warm_pastels 
##               9               6               9               9               9 
##           waves   winter_bright  winter_bright2     winter_soft    wool_muffler 
##               5               9               9               9               9

使用几个试试看:

p1 <- base + scale_fill_prism(palette = "colorblind_safe")
p2 <- base + scale_fill_prism(palette = "neon")

p1 + p2

shape

提供了3套形状

ggprism_data$shape_palettes
## $complete
## # A tibble: 14 x 2
##    name                   pch
##    <chr>                <dbl>
##  1 circle small            16
##  2 square                  15
##  3 triangle                17
##  4 diamond                 18
##  5 circle filled           21
##  6 square filled           22
##  7 triangle filled         24
##  8 triangle down filled    25
##  9 diamond filled          23
## 10 asterisk                 8
## 11 plus                     3
## 12 cross                    4
## 13 circle plus             10
## 14 square cross             7
## 
## $default
## # A tibble: 9 x 2
##   name           pch
##   <chr>        <dbl>
## 1 circle small    16
## 2 square          15
## 3 triangle        17
## 4 diamond         18
## 5 asterisk         8
## 6 plus             3
## 7 cross            4
## 8 circle plus     10
## 9 square cross     7
## 
## $filled
## # A tibble: 10 x 2
##    name                   pch
##    <chr>                <dbl>
##  1 circle filled           21
##  2 square filled           22
##  3 triangle filled         24
##  4 triangle down filled    25
##  5 diamond filled          23
##  6 asterisk                 8
##  7 plus                     3
##  8 cross                    4
##  9 circle plus             10
## 10 square cross             7

使用不同的形状:

base <- ggplot(mpg, aes(x = displ, y = cty)) +
  geom_point(aes(colour = class, fill = class, shape = class)) + 
  theme_prism(base_size = 11, base_fontface = "plain", border = TRUE) +
  theme(plot.subtitle = element_text(face = "bold"),
        legend.position = c(0.80.75),
        legend.key.height = unit(10"pt")) +
  coord_cartesian(clip = "off") + 
  scale_colour_prism(palette = "floral") + 
  scale_fill_prism(palette = "floral")


p1 <- base
p2 <- base + scale_shape_prism(palette = "default") + 
  labs(subtitle = "default")
p3 <- base + scale_shape_prism(palette = "filled") + 
  labs(subtitle = "filled")
p4 <- base + scale_shape_prism(palette = "complete") + 
  labs(subtitle = "complete")

(p1 + p2) / (p3 + p4)



以上就是今天的内容,希望对你有帮助哦!欢迎点赞、在看、关注、转发

欢迎在评论区留言或直接添加我的微信!




欢迎关注我的公众号:医学和生信笔记

医学和生信笔记 公众号主要分享:1.医学小知识、肛肠科小知识;2.R语言和Python相关的数据分析、可视化、机器学习等;3.生物信息学学习资料和自己的学习笔记!


往期精彩内容:

让你的ggplot2主题支持markdown和css


让你的ggplot2支持markdown语法


ggpairs展示数据间的相关性


ggduo展示两组数据间的相关性


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存