打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

简介

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)

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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Graphpad Prism太贵,试试ggprism!
一键获取graphpad同款主题
Graphpad Prism 8.0绘制XY轴双误差线图
最强合集17个论文画图技巧丨教师节献礼
GraphPad prism8安装教程
GraphPad Prism进阶技巧(一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服