Polar plot (ggplot2), outer ring removed, grid on top

742 views Asked by At

I've searched and re-searched through the different questions and although I've seen similar ones (some very helpful indeed) I can't seem to find an answer for this.

I'm working with polar plots, by default these plots add an extra outside ring which I don't want. I've managed to get rid of it by removing [panel.grid] and using instead [geom.hline].

Here is my problem:

  • if I use panel.ontop=FALSE , the grid lines show underneath the plot and I loose the unit reference (which I need)(e.g. one cannot see where the division corresponding to 1 is)

  • if I use panel.ontop=TRUE, I loose the grid lines

What I would like is to have the plot with the grid lines on top (and without the outermost ring). Here you can see an example of my code:

##Data
Main.Actions <- c("Financing","Anchoring regulations", "Awareness", "Sewage", "Enforcement", "Coordination")
count<-c(2, 2,4,2,3,3)
improve<-data.frame(Main.Actions, count, stringsAsFactors = FALSE)

## Plot

MA4<- ggplot(improve, aes(x = Main.Actions, y=count, fill=Main.Actions, width=1)) +
  geom_hline(yintercept = seq(0, 4, by = 1), colour = "grey", size = 0.35) +
  theme(
    panel.grid.major.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_blank(),
    panel.ontop = FALSE,
    legend.position = "none",
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text.y=element_blank(),
    axis.text.x=element_blank(),
    axis.ticks.y=element_blank())+

  theme(plot.margin=unit(c(0,0,0,0),"cm"))+

  geom_bar(stat="identity")+scale_fill_brewer(palette = "Blues") + 
  coord_polar()

MA4

enter image description here

I'm sure it's something very simple but for the life of me that I've spent 3 days on this and can't get it right.

Any help will be immensely appreciated,

Ana

1

There are 1 answers

0
Ana Ruiz Frau On

Solved!!

I placed the [geom_hline] after the [geom_bar] and now it draws just what I needed. I hope this can be helpful for other users. Find code below:

MA4<- ggplot(improve, aes(x = Main.Actions, y=count, fill=Main.Actions, width=1)) +

  theme(
    panel.grid.major.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_blank(),
    panel.ontop =FALSE,
    legend.position = "none",
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text.y=element_blank(),
    axis.text.x=element_blank(),
    axis.ticks.y=element_blank())+

  theme(plot.margin=unit(c(0,0,0,0),"cm"))+

  geom_bar(stat="identity")+scale_fill_brewer(palette = "Blues") + 
  geom_hline(yintercept = seq(0, 4, by = 1), colour = "darkgrey", size = 0.35) +
  coord_polar()