manipulate delineation of geom_bar and coord_polar in ggplot2 r
Asked Answered
M

1

6

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

Concentric circles

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?

Mcilwain answered 31/8, 2018 at 22:17 Comment(2)
Hackish & dirty, but without fiddling around with geom_rect, maybe overplot the fill colors ggplot(df,aes(x=factor(1),fill=C))+ geom_bar(width = 1, color = "black")+ coord_polar()+ geom_col(aes(x=0.5, y=1, color=C), width=0)Rhodia
Thanks for this. This is a potential solution, but the colours in geom_col would need to use B as the scale. I can't make that happen just by replacing C with B within geom_col...Mcilwain
C
6

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

plot

Carcanet answered 1/9, 2018 at 2:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.