Creating pie charts without numbering / axis ticks in ggplot2

I study my path through ggplot2, and I used it to use polar coordinates and create pie charts, and I ran into some problems.

I want to create a pie chart that does not have a zero or zero axis. The sample code that I have that I thought should work:

data = data.frame(Category = c("A", "B", "C", "D"), Value = runif(4)) ggplot(data, aes(0, weight = Value, fill = Category)) + scale_x_continuous(breaks = NA) + scale_y_continuous(breaks = NA) + geom_bar(binwidth = 1) + coord_polar(theta = "y") + scale_fill_brewer(pal = "Set1") 

This code gives me an error:

 Error in if (ends_apart < 0.05) { : argument is of length zero 

Omitting the breaks argument in the scale_y_continuous function results in a successful plot, with the exception of numbering and radius marking of the pie chart. Omitting the coord_polar function (and leaving the breaks argument to scale_y_continuous), the result is a bar graph without numbering or tick x or y.

I found several solutions related to changing label parameters, and this should be a great workaround, but I was curious why I get this error.

As a side note: I uninstalled and reinstalled ggplot2 to make sure I have the latest version installed and all the checksums match.

Edit: To clarify what I need, it is something like:

plot

except numbering in a pie chart.

+4
source share
1 answer

I think this is what you need:

 ggplot(data,aes(x = factor(0),y = Value,fill = Category)) + geom_bar(stat = "identity",position = "fill") + scale_fill_brewer(palette = 'Set1') + coord_polar(theta = "y") + opts(axis.ticks = theme_blank(), axis.text.y = theme_blank(), axis.text.x = theme_blank()) 

Note Since version 0.9.2 opts been replaced with theme :

 + theme(axis.ticks = element_blank(), axis.text.y = element_blank(), axis.text.x = element_blank()) 
+8
source

All Articles