R-ggCyberPunk包简介
R-ggCyberPunk包作为基于ggplot2、专门绘制赛博朋克风的第三方包,其提供的绘制函数有限,主要包括以下几个:
geom_glowing_area()
:绘制赛博朋克风发光区域图(area plot)。geom_glowing_line()
:绘制赛博朋克风发光线图(line plot )。geom_linesaber()
:绘制赛博朋克风激光剑外观线图(line plot)。theme_cyberpunk()
:绘制赛博朋克风绘图主题。
更多参数信息可参考:R-ggCyberPunk介绍
R-ggCyberPunk包实例演示
这一部分就列举使用几个 R-ggCyberPunk包绘制赛博朋克风的可视化作品,如下:
「geom_glowing_area()
」:
library(tidyverse)
library(ggtext)
library(hrbrthemes)
library(ggCyberPunk)
df = data.frame(A=c(1,4,4,6,7,5,1),
B=c(4,3,5,7,5,6,7),
Time=c(1,2,3,4,5,6,7)) %>%
# 将数据准换成DF类型
pivot_longer(cols = c(A,B),names_to = "group", values_to = "count")
#可视化绘制
plot01 <- ggplot(data = df,aes(x=Time, y = count, color = group, fill= group))+
geom_glowing_area()+
scale_fill_cyberpunk("zune")+
scale_color_cyberpunk("zune")+
labs(
title = "Example of <span style='color:#D20F26'>ggCyberPunk::geom_glowing_area function</span>",
subtitle = "processed charts with <span style='color:#1A73E8'>geom_glowing_area()</span>",
caption = "Visualization by <span style='color:#0057FF'>DataCharm</span>") +
theme_cyberpunk(font = "Roboto Condensed")+
theme(
plot.title = element_markdown(hjust = 0.5,vjust = .5,color = "black",
size = 20, margin = margin(t = 1, b = 12)),
plot.subtitle = element_markdown(hjust = 0,vjust = .5,size=15),
plot.caption = element_markdown(hjust = 1,face = 'bold',size = 12)
)
Example Of geom_glowing_area()with zune
注意:这里scale_fill_cyberpunk()
中可设置main
, zune
,cotton candy
, laser sword
四种选项。效果分别如下:
「main
」:
Example Of geom_glowing_area()with main
「cotton candy
」:
Example Of geom_glowing_area()with cotton candy
「laser sword
」:
Example Of geom_glowing_area()with laser sword
「geom_glowing_line()
」:
df = data.frame(A=c(1,4,4,6,7,5,1),
B=c(4,3,5,7,5,6,7),
Time=c(1,2,3,4,5,6,7)) %>%
pivot_longer(cols = c(A,B),names_to = "group", values_to = "count")
plot2 <- ggplot(data = df,aes(x=Time, y = count, color = group, fill= group))+
geom_glowing_line()+
scale_color_cyberpunk()+
labs(
title = "Example of <span style='color:#D20F26'>ggCyberPunk::geom_glowing_line function</span>",
subtitle = "processed charts with <span style='color:#1A73E8'>geom_glowing_line()</span>",
caption = "Visualization by <span style='color:#0057FF'>DataCharm</span>") +
theme_cyberpunk(font = "Roboto Condensed")+
theme(
plot.title = element_markdown(hjust = 0.5,vjust = .5,color = "black",
size = 20, margin = margin(t = 1, b = 12)),
plot.subtitle = element_markdown(hjust = 0,vjust = .5,size=15),
plot.caption = element_markdown(hjust = 1,face = 'bold',size = 12)
)
Example Of geom_glowing_line()
「geom_linesaber()
」:
df = data.frame(A=c(1,4,4,6,7,5,1),
B=c(4,3,5,7,5,6,7),
Time=c(1,2,3,4,5,6,7)) %>%
pivot_longer(cols = c(A,B),names_to = "group", values_to = "count")
plot3 <- ggplot(data = df,aes(x=Time, y = count, color = group, fill= group))+
geom_linesaber()+
theme_cyberpunk()+
scale_color_cyberpunk(reverse = T)+
labs(
title = "Example of <span style='color:#D20F26'>ggCyberPunk::geom_linesaber function</span>",
subtitle = "processed charts with <span style='color:#1A73E8'>geom_linesaber()</span>",
caption = "Visualization by <span style='color:#0057FF'>DataCharm</span>") +
theme_cyberpunk(font = "Roboto Condensed")+
theme(
plot.title = element_markdown(hjust = 0.5,vjust = .5,color = "black",
size = 20, margin = margin(t = 1, b = 12)),
plot.subtitle = element_markdown(hjust = 0,vjust = .5,size=15),
plot.caption = element_markdown(hjust = 1,face = 'bold',size = 12)
)
Example Of geom_linesaber()
以上就是简单介绍了R-ggCyberPunk包三个绘图函数,接下里,使用改包主题对常见图表进行朋克风格图表绘制,如下:
「geom_boxplot」:箱线图
plot4 <- ggplot(mpg, aes(class, hwy,fill=factor(drv))) +
geom_boxplot() +
scale_fill_cyberpunk("zune",name="")+
labs(
title = "Example of <span style='color:#D20F26'>ggCyberPunk::scale_fill_cyberpunk function</span>",
subtitle = "processed charts with <span style='color:#1A73E8'>scale_fill_cyberpunk()</span>",
caption = "Visualization by <span style='color:#0057FF'>DataCharm</span>") +
theme_cyberpunk(font = "Roboto Condensed")+
theme(
plot.title = element_markdown(hjust = 0.5,vjust = .5,color = "black",
size = 20, margin = margin(t = 1, b = 12)),
plot.subtitle = element_markdown(hjust = 0,vjust = .5,size=15),
plot.caption = element_markdown(hjust = 1,face = 'bold',size = 12)
)
Example Of ggplot2::geom_boxplot() with theme_cyberpunk()
当然,还可以设置其他颜色风格的样式。如果不喜欢R绘制类似的图表,可以试试python的可视化库-mplcyberpunk,更多关于mplcyberpunk库的详细内容大家可参考:Python-mplcyberpunk库
参考资料
R-ggCyberPunk介绍:https://github.com/delabj/ggCyberPunk
python-mplcyberpunk库:https://github.com/dhaitz/mplcyberpunk