可能是一个简单的
是否可以消除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()
例如,在上面的图中是消除黑色边框线还是使其颜色与填充颜色相同?
还有另一个问题,是否可以仅从饼图的外围消除边界线?因此,仅保留切片的标记?
答案 0 :(得分:2)
您可以在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()
答案 1 :(得分:2)
ggplot通常对颜色使用两个参数:
col =
和
fill =
您分配了填充(内部),但没有处理col(轮廓)。
以下应该工作,我分配col = NA
ggplot(pie) +
geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount,
fill = state, explode = focus), col=NA,stat = 'pie') +
scale_fill_brewer('', palette = 'Set1') +
coord_fixed()
编辑:所以要回答第二个问题-我真的不知道这是否可行(我对ggforce不太熟悉) 有鉴于此,我想在此针对您问题的“棘手”解决方案之前请求原谅。但是我觉得最好为别人提供一些改进的地方。
说明:保留原始轮廓,然后使用geom_arc0函数绘制与每个线段相同颜色的新轮廓”。
geom_arc0(aes(x0 = 0, y0 = 0, r = 1, start = start, end = end,
colour = factor(state)), data = pie, ncp = 50)
在上下文中:
ggplot(pie) +
geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount,
fill = state, explode = focus), col="black",stat = 'pie') +
geom_arc0(aes(x0 = 0, y0 = 0, r = 1, start = start, end = end,
colour = factor(state)), data = pie, ncp = 50)
scale_fill_brewer('', palette = 'Set1') +
coord_fixed()
它看起来有点狡猾-如果您增加ncp参数,则会在轮廓上添加更多点(因此越来越接近完美的圆)-我仅限于ncp = 2000。
再次道歉,因为它太黑了。