I am making a pie chart to go along with a series of plots all made in ggplot2. The data I'm using have two categories broken in to a total of three subcategories. Basically, the data look like this:
Category Category_Value Super_Category
<fctr> <dbl> <dbl>
1 A 0.03733874 1
2 B 0.66732754 0
3 C 0.29533372 1
Here is the basic pie chart I have at the subcategory level:
And here is what I'd like to have (or something similar):
I had never made a pie chart in ggplot2 before, so here is my basic code to generate the top plot:
pie.chart <- ggplot(pie.data, aes(x = "", y = Category_Value, fill = Category, width = 1)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) +
scale_fill_manual(values = c("#4DAF4A", "#377EB8", "#E41A1C")) +
theme_bw() +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank()
)
Is this something that's doable? I messed around with making another plot grouped at the major category level and overlaying them without success.
You could use annotate
to get an approximation of your picture.
Firstly I've used your small subset of data
pie.data <- data.frame(
Category = c("A", "B", "C"),
Category_Value = c(0.03733874, 0.66732754, 0.29533372),
Super_Category = c(1,0,1))
Then I've appplied your code
pie.chart <- ggplot(pie.data, aes(x = "", y = Category_Value, fill = Category, width = 1)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0) +
scale_fill_manual(values = c("#4DAF4A", "#377EB8", "#E41A1C")) +
theme_bw() +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank()
)
And Finnaly I drew line using
pie.chart + annotate("rect", xmin = 1.5, xmax = 1.9, ymin = 0,2, ymax = 0.30, alpha=0,colour = "black")
And the output:
Note that because you have more data that my sample you will have to play with the settings values of ymin = 0,2
, ymax = 0.30
in annotate
in order your line will cover values that you want.