ggpomological——为ggplot2使用素描风格

ggpomological——为ggplot2使用素描风格

该包的GitHub地址为:gadenbuie/ggpomological,可以为ggplot2图像添加手绘风格。

安装

1
devtools::install_github("gadenbuie/ggpomological", build_vignettes=TRUE)

色板

填充色

1
scales::show_col(ggpomological:::pomological_palette)

背景色

1
scales::show_col(unlist(ggpomological:::pomological_base))

主题和标度

三个主题函数:

  1. theme_pomological();
  2. theme_pomological_plain();
  3. theme_pomological_fancy()。

两个标度:

  1. scale_color_pomological();
  2. scale_fill_pomological()。

示例

1
2
3
4
5
6
7
library(ggplot2, help, pos = 2, lib.loc = NULL)
library(ggpomological, help, pos = 2, lib.loc = NULL)
library(dplyr, help, pos = 2, lib.loc = NULL)

(basic_iris_plot <- ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width, colour = Species) +
geom_point(size = 2))

使用pomological颜色标度:

1
(basic_iris_plot <- basic_iris_plot + scale_color_pomological())

使用pomological主题:

1
2
3
basic_iris_plot +
theme_pomological(base_size = 20, base_family = 'MLingWaiMedium-SC') +
xlab("萼片长度") + ylab("萼片宽度") + scale_color_pomological("品种")

使用pomological_plain主题

1
2
3
basic_iris_plot +
theme_pomological_plain(base_size = 20, base_family = 'MLingWaiMedium-SC') +
xlab("萼片长度") + ylab("萼片宽度") + scale_color_pomological("品种")

使用pomological_fancy主题

1
2
3
basic_iris_plot +
theme_pomological_fancy(base_size = 20, base_family = 'MLingWaiMedium-SC') +
xlab("萼片长度") + ylab("萼片宽度") + scale_color_pomological("品种")

对柱形图使用该主题:

1
2
3
4
5
6
7
8
9
(stacked_bar_plot <- ggplot(diamonds) +
aes(price, fill = cut) +
geom_histogram(binwidth = 850) +
xlab('价格(美元)') +
ylab('数量') +
ggtitle("ggpomological") +
scale_x_continuous(label = scales::dollar_format()) +
scale_fill_pomological())
stacked_bar_plot + theme_pomological_fancy(base_size = 20, base_family = 'MLingWaiMedium-SC')

密度图

1
2
3
4
5
6
7
8
9
10
11
density_plot <- mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
aes(mpg, fill = cyl, color = cyl) +
geom_density(alpha = 0.75) +
labs(fill = '汽缸类型', colour = '汽缸类型', x = '每英里耗油数', y = '密度') +
scale_color_pomological() +
scale_fill_pomological() + theme_pomological(
base_size = 20, base_family = 'MLingWaiMedium-SC'
)
print(density_plot)

点和线:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(big_volume_cities <- txhousing %>%
group_by(city) %>%
summarize(mean_volume = mean(volume, na.rm = T)) %>%
arrange(-mean_volume) %>%
top_n(length(ggpomological:::pomological_palette)) %>%
pull(city))

# [1] "Houston" "Dallas" "Austin"
# [4] "San Antonio" "Collin County" "Fort Bend"
# [7] "NE Tarrant County" "Montgomery County" "Denton County"

full_bar_stack_plot <- txhousing %>%
filter(city %in% big_volume_cities) %>%
group_by(city, year) %>%
summarize(mean_volume = mean(volume, na.rm = T)) %>%
ungroup %>%
mutate(city = factor(city, big_volume_cities)) %>%
ggplot() +
aes(year, mean_volume, fill = city, group = city) +
geom_col(position = 'fill', width = 0.9) +
labs(x = '年份', y = '平均流量', color = '城市') +
theme(panel.grid.minor.x = element_blank()) +
scale_fill_pomological()
print(full_bar_stack_plot +
theme_pomological(base_size = 20, base_family = 'MLingWaiMedium-SC'))

山岭图:

1
2
3
4
5
6
7
8
9
10
11
(ridges_pomological <- ggplot(diamonds) +
aes(x = carat, y = clarity, color = clarity, fill = clarity) +
ggridges::geom_density_ridges(alpha = 0.75) +
theme_pomological(
base_size = 20,
base_family = 'MLingWaiMedium-SC',
base_theme = ggridges::theme_ridges()
) +
scale_fill_pomological() +
scale_color_pomological() +
labs(x = "克拉", y = "清晰度", color = "清晰度", fill = "清晰度"))

# R

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×