在ggplot2 r中操纵geom_bar和coord_polar的描述

问题描述 投票:6回答:1

我正在使用ggplot中的polar_coord建立一个同心圆图表,我需要摆脱一条特定的线。这是代码和情节:

df <- data.frame(A=letters[1:12],
                 B=c(rep("Dim_1",4),rep("Dim_2",4),rep("Dim_3",4)),
                 C=c(rep("Ind_1",2),rep("Ind_2",2),rep("Ind_3",2),rep("Ind_2",2),rep("Ind_5",2),rep("Ind_6",2)))

ggplot(df,aes(factor(1),fill=C))+
  geom_bar(width = 1,colour="black")+
  coord_polar()+
  scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"))

Concentric circles

如何摆脱从圆心到顶部的线?由于这张极坐标图是用条形图(geom_bar)制作的,另一种提问方式是,我如何摆脱每个酒吧底部的边界,而不是侧面或顶部?

r ggplot2 geom-bar
1个回答
6
投票

看看以下是否适合您?注释代码中的说明:

ggplot(df, aes(factor(1), fill = C)) +
  geom_bar(width = 1, colour = NA) +                       # hide all outlines in geom_bar
  stat_count(aes(yintercept = cumsum(rev(..count..))),     # add only the top line for each
             geom = "hline") +                             # bar in the stack
  coord_polar() +

  # optional: add black outline to the fill legend
  scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"),
                    guide = guide_legend(override.aes = list(color = "black")))

plot

© www.soinside.com 2019 - 2024. All rights reserved.