作者:何包蛋0727 | 来源:互联网 | 2022-12-06 04:20
我正在使用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"))
如何摆脱从圆心到顶部的线?由于这张极坐标图是用条形图(geom_bar
)制作的,另一种提问方式是,我如何摆脱每个酒吧底部的边框,而不是侧边或顶部?
1> Z.Lin..:
看看以下是否适合您?注释代码中的说明:
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")))