Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polar Bar Plot, with inner-most circle empty Using R

I wanted a circular bar plot like shown below:

enter image description here But right now, I have only: enter image description here

To make this I used the following code in R:

require(ggplot2)
ggplot(PolarPlot,aes(x,y,
                     fill=x))+
      geom_bar(width=1,stat="identity")+
      coord_polar() + xlab("")+ylab("")+
  theme(legend.position = "none" , axis.text.y = element_blank() ,
        axis.ticks = element_blank()

Could someone tell what modifications I need to make to get my desired graph?

The data is as follows:

PolarPlot <- structure(list(x = structure(1:7, .Label = c("Class1", "Class2", 
    "Class3", "Class4", "Class5", "Class6", "Class7"), class = "factor"), 
    y = c(2L, 8L, 17L, 56L, 28L, 7L, 2L)), .Names = c("x", "y"),
    class = "data.frame", row.names = c(NA, -7L))
like image 420
204 Avatar asked Jul 29 '16 12:07

204


1 Answers

You produce your plot by first creating a bar plot and then converting it to polar coordinates (which is fine). If you want the bars not to start at the center in the polar plot, then you need to make sure that they don't start at the bottom in the bar plot.

What I mean is easiest explained by actually showing it. First, I create the bar plot the same way as you do, but I extend the y-axis to reach to negative values:

p <- ggplot(PolarPlot, aes(x, y, fill=x)) +
      geom_bar(width=1,stat="identity") +
      xlab("") + ylab("") +
      theme(legend.position = "none" , axis.text.y = element_blank() ,
            axis.ticks = element_blank()) +
      scale_y_continuous(limits = c(-50, 60))

enter image description here

When I switch to polar coordinates, the gap at he lower end of the bar plot is converted into a gap at the center of the polar plot:

p + coord_polar()

enter image description here

You can modify the size of the gap at the center by playing with the values used for limits in scale_y_continuous().

like image 100
Stibu Avatar answered Oct 01 '22 07:10

Stibu