R绘图 | 圆角堆叠柱状图(ggchicklet )

简介: R绘图 | 圆角堆叠柱状图(ggchicklet )

绘制

# 安装并加载包
# 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)

image.png

ggchicklet


参考


https://github.com/neilcuz/tidytuesday/blob/


相关文章
|
算法 测试技术 C++
C++算法:柱状图中最大的矩形
C++算法:柱状图中最大的矩形
|
2月前
|
图形学
利用Graphics画出一幅图表绘制折线图
("某工厂某产品年度销售额图表",this.Font, Brushes.Black, new Point(420,14)); pen.Dispose();
20 0
echarts折线图折线点大小,颜色,折线的颜色设置
echarts折线图折线点大小,颜色,折线的颜色设置
99 1
echarts折线图线条颜色和区域颜色设置
echarts折线图线条颜色和区域颜色设置
220 0
38Echarts - 柱状图(极坐标系下的堆叠柱状图)
38Echarts - 柱状图(极坐标系下的堆叠柱状图)
124 0
36Echarts - 柱状图(极坐标系下的堆叠柱状图)
36Echarts - 柱状图(极坐标系下的堆叠柱状图)
53 0
37Echarts - 柱状图(极坐标系下的堆叠柱状图)
37Echarts - 柱状图(极坐标系下的堆叠柱状图)
76 0
|
前端开发
echart折线图堆叠 y轴和实际数据不对应
echart折线图堆叠 y轴和实际数据不对应
171 0
|
前端开发
Echarts柱状图y轴刻度标签图片和柱状渐变功能实现的解决方案
Echarts柱状图y轴刻度标签图片和柱状渐变功能实现的解决方案
279 0
echart渐变折线图,立体柱状图,发光饼图,月份图等
echart渐变折线图,立体柱状图,发光饼图,月份图等