r - 使用 ggplot 在饼图中心打洞

标签 r ggplot2 pie-chart

我想不通,为什么ggplot在下图的中间绘制一个整体:

enter image description here

这里的数据和代码:

dat15 <- data.frame("Insgesamt" = c(64, 20, 13, 3),
              "18-29" = c(41, 25, 27, 7),
              "30-44" = c(58, 25, 12, 5),
              "45-59"=c(69, 20, 10, 1),
              "60+" = c(76, 14, 9, 1),
              "Arbeiter" = c(57, 34, 9, 0),
              "Angestellte" = c(69, 17, 11, 3),
              "Beamte" = c(72, 12, 11, 5),
              "Selbstständige" = c(69, 23, 5, 3),
              "unter 1000" = c(47, 30, 19, 4),
              "1000-2000" = c(59, 24, 15, 2),
              "2000-3000" = c(72, 15, 10, 3),
              "3000+" = c(68, 19, 10, 3),
              "seit Geburt" = c(65, 19, 12, 4),
              "zugez. vor 20" = c(72, 17, 9, 2),
              "zugez. in 20" = c(46, 28, 19, 7),
              row.names = c("zum Vorteil", "zum Nachteil", "keine Veränderung", "weiß nicht"))

dat15 <- melt(dat15)
dat15$type = c("zum Vorteil", "zum Nachteil", "keine Veränderung", "weiß nicht")
dat15.1 <- dat15[c(1:4),]
dat15.1$labelpos <- cumsum(dat15.1$value) - dat15.1$value / 2


plot15.1 <- ggplot()  + 
    theme_m(base_family = family,base_size=size) + xlab("") + ylab("") 

plot15.1 <- plot15.1 + 
    geom_bar(ata = dat15.1, aes(x = dat15.1$variable, y = dat15.1$value, 
        fill=dat15.1$type), stat = 'identity')

plot15.1 <- plot15.1 + coord_polar("y", start = 0)

最佳答案

如果您添加参数 width = 1 它将起作用至 geom_bar :

ggplot()  + 
  geom_bar(data = dat15.1, aes(x = variable, y = value, fill = type), 
           stat = 'identity', width = 1) + 
  coord_polar("y", start = 0)

enter image description here

关于r - 使用 ggplot 在饼图中心打洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27231840/

相关文章:

r - 如何在R中找到相似的句子/短语?

r - 未指定 aes() 颜色和形状时 ggplot 中的图例

r - 使用 ggplot 显示 y 最大值的位置

RMarkdown 和 ggplot : Axis labels cut off

r - 将多个数据帧传递到函数中以使用map_dfr生成数据帧

r shiny 数据表有时不显示

r - 使用 Caret 包进行随机森林(回归)时出错

javascript - D3 多个饼图标签

javascript - 解决: C3 - Labels not showing in C3 pie chart whit narrow arcs

时间:2019-05-17 标签:c#devexpresspichart系列点颜色变化