I wanted a circular bar plot like shown below:
But right now, I have only:
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))
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))
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()
You can modify the size of the gap at the center by playing with the values used for limits
in scale_y_continuous()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With