绘制
# 安装并加载包 # install.packages("ggchicklet", repos = "https://cinc.rud.is") library(tidyverse) library(ggplot2) library(ggchicklet) library(prismatic) library(ggtext) df = read.csv('df_0610.csv') # 设置标题及字符颜色 title = "Are they <span style='color:#FF0000;'>r</span><span style='color:#FFDB00;'>a</span><span style='color:#49FF00;'>i</span><span style='color:#00FF92;'>n</span><span style='color:#0092FF;'>b</span><span style='color:#4900FF;'>o</span><span style='color:#FF00DB;'>w</span>-<span style='color:#FF0000;'>w</span><span style='color:#FFDB00;'>a</span><span style='color:#49FF00;'>s</span><span style='color:#00FF92;'>h</span><span style='color:#0092FF;'>i</span><span style='color:#4900FF;'>n</span><span style='color:#FF00DB;'>g</span> you? " df %>% ggplot(aes(x = year, y = sum, fill = fct_rev(comp))) + geom_chicklet(aes(color = after_scale(clr_darken(fill, 0.5))), alpha = .75, show.legend = FALSE) + geom_point(aes(x = -83, y = 40, fill = comp), size=4, alpha = .8, shape = 21) + scale_fill_manual(values = c("black", rev(rainbow(7)), "black")) + scale_x_continuous(breaks = seq(2012, 2023, 1), limits = c(2012.5, 2022.5)) + scale_y_continuous(breaks = seq(0, 600000, 100000), labels = c("0", "100K", "200K", "300K", "400K", "500K", "600K") ) + labs( title = title, x = "", y = "Dollars donated to anti-LGBTQ politicians" ) + theme_minimal(base_size=9, base_family="Consolas") + theme( plot.title.position = 'plot', plot.title = element_markdown(face = 'bold', size = 15, hjust = 0), plot.margin = margin(10, 15, 10, 10), axis.text = element_text(color = "gray10"), axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)), legend.position = "top", legend.title = element_blank(), legend.text = element_text(size = 8) ) + guides(fill=guide_legend(nrow = 2, byrow = FALSE, reverse = TRUE)) ggsave("rainbow-washing.png", w = 6, h = 6, dpi = 300)
ggchicklet
参考
https://github.com/neilcuz/tidytuesday/blob/