在ggplot2 r中操纵geom_bar和coord_polar的描述 [英] manipulate delineation of geom_bar and coord_polar in ggplot2 r

查看:265
本文介绍了在ggplot2 r中操纵geom_bar和coord_polar的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am building a chart of concentric circles using polar_coord in ggplot and I need to get rid of a specific line. Here's the code and the plot:

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)制成的,因此提出问题的另一种方法是,如何摆脱每个条形图底部的边框,而不是侧面或顶部的边框?

How do I get rid of the line that goes from the centre of the circle to its top? Since this polar chart was made out of a bar chart (geom_bar), another way of asking the question is, how do I get rid of the border at the base of each bar but not on the sides or top?

推荐答案

看看以下内容是否对您有用?注释代码中的解释:

See if the following works for you? Explanations in annotated code:

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")))

这篇关于在ggplot2 r中操纵geom_bar和coord_polar的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆