本文主要展示如何ggprism包中自带的45种调色板填充颜色运用到R语言的ggplot2绘图中,如下图所示。更多内容可关注微信公众号【日常分享的小懒猫】。
1、数据准备
利用diamonds数据集,绘制不同颜色分组下钻石价格的箱线图,分别进行45种颜色的填充。
library(ggplot2)
library(ggprism)
#绘图
ggplot(diamonds, aes(color, price, fill = color)) +
geom_boxplot(outlier.shape = NA) +
scale_y_continuous(limits = c(0, 15000)) +
theme(legend.position = "none") +
scale_fill_prism(palette = "summer") +
annotate("text", x = 3, y = 13500, label = "summer", size = 9, color = "red")
2、填充色彩
ggprism包中共包含45种调色板名称,可配合ggplot2绘图使用。在使用的过程中,通过添加图层函数scale_fill_prism(palette = "name") 即可,其中name为调色板名称,45种调色板名称如下:
#具体颜色
ggprism_data$fill_palettes
#$autumn_leaves
#[1] "#A00000" "#FF0000" "#CE0665" "#FF8080" "#9F044D" "#F94040" "#FF6000" "#CE0665" "#C06000"
#$beer_and_ales
#[1] "#94641F" "#C5944E" "#D79A40" "#C0B57B" "#804040" "#BB5E00" "#CD751D" "#910000" "#A25100"
#$black_and_white
#[1] "#000000" "#A0A0A4" "#808080" "#D4D4D4" "#606060" "#A0A0A4" "#606060" "#E8E8E8" "#A0A0A4"
#调色板名称
names(ggprism_data$fill_palettes)
1 autumn_leaves
2 beer_and_ales
3 black_and_white
4 blueprint
5 candy_bright
6 candy_soft
7 colorblind_safe
8 colors
9 diazo
10 earth_tones
11 evergreen
12 fir
13 flames
14 floral
15 greenwash
16 inferno
17 magma
18 mustard_field
19 muted_rainbow
20 neon
21 ocean
22 office
23 pastels
24 pearl
25 plasma
26 prism_dark
27 prism_light
28 purple_passion
29 quiet
30 shades_of_gray
31 spring
32 stained_glass
33 starry
34 summer
35 sunny_garden
36 the_blues
37 viridis
38 warm_and_sunny
39 warm_and_sunny2
40 warm_pastels
41 waves
42 winter_bright
43 winter_bright2
44 winter_soft
45 wool_muffler
3、绘图展示
以下为45种调色板对应的45幅图,图中红色字体即为调色板名称。





4、其他
其他绘图方法可进一步阅读公众号其他文章。更多内容可关注微信公众号【日常分享的小懒猫】。
如有帮助请多多点赞哦!
文章转载自日常分享的小懒猫,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




