首页 > 解决方案 > ggforce::geom_arc_bar 中的线条颜色

问题描述

大概是一个简单的。

有没有办法消除 ggforce::geom_arc_bar 饼图中的边界线?

pie <- data.frame(
    state = c('eaten', 'eaten but said you didn\'t', 'cat took it', 
              'for tonight', 'will decompose slowly'),
    focus = c(0.2, 0, 0, 0, 0),
    start = c(0, 1, 2, 3, 4),
    end = c(1, 2, 3, 4, 2*pi),
    amount = c(4,3, 1, 1.5, 6),
    stringsAsFactors = FALSE
)
ggplot(pie) + 
    geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount, 
                     fill = state, explode = focus), stat = 'pie') + 
    scale_fill_brewer('', palette = 'Set1') +
    coord_fixed()

在此处输入图像描述

例如,在上图中,要么消除黑色边框线,要么使其颜色与填充颜色相同?

还有一个问题,是否可以只从馅饼的周边消除边界线?那么只有切片的分界线会保留吗?

标签: rggplot2colorsggforce

解决方案


您可以添加color = "transparent"color = NA里面geom_arc_bar

在此处输入图像描述

代码

library(ggforce)
ggplot(pie) + 
  geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount, 
                   fill = state, explode = focus), stat = 'pie',
                   color = "transparent") + 
  scale_fill_brewer('', palette = 'Set1') +
  coord_fixed()

推荐阅读