Let's say I have this simple data:
mydata <- data.frame(group=c("A", "B", "0", "AB"), FR=c(20, 32, 32, 16))
If I want to create a pie chart from this dataframe I can do:
with(mydata,pie(FR, labels=paste0(as.character(group), " ", FR, "%"), radius=1))
It's quite simple but acceptable.
How can I get something similar with ggplot2 or lattice?
After much trial and error I've got
ggplot(mydata, aes(x = factor(1), y=FR,fill=factor(group)) ) + geom_bar(width = 1,stat="identity")+coord_polar(theta = "y")
It's much more complex and ugly. Isn't it supposed to be easy? ggplot books only give some examples and discourage from using pie charts.
Lattice is even worse, you need many many lines to get it's scaring.
Could anybody help me top get a nice and simple Pie chart, please? For example something like...
Isn't there any R package able to do it easily, without 20 lines of code?
You can try with the pie3D()
function from the plotrix
package:
library(plotrix)
pie3D(mydata$FR, labels = mydata$group, main = "An exploded 3D pie chart", explode=0.1, radius=.9, labelcex = 1.2, start=0.7)