1

Given a dataset with a factor column (X1) and a subtotal column (X2)

  X1 X2 
1  1  12  
2  2  200 
3  3  23  
4  4  86  
5  5  141  

I would like to create a graphic like this:

like so

which gives x2 as a percentage of the X2 total, divided by X1.

Edit: clarity and adding dataset for reproducability

Jaap
  • 81,064
  • 34
  • 182
  • 193
sgdata
  • 2,543
  • 1
  • 19
  • 44
  • 2
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). As the question currently stands it can be considered a tool/tutorial request, which is a reason for voting to close. – Jaap Jun 05 '16 at 16:45
  • Sure, I've edited to fit better. Does this help? – sgdata Jun 05 '16 at 17:23

1 Answers1

5

For example

set.seed(1234)
df <- data.frame(x = 1:6)
df$y <- runif(nrow(df))
df$type <- sample(letters, nrow(df))
ggplot(df, aes(x+-.5, y, fill=type)) + 
  geom_bar(stat="identity", width=1) + 
  coord_polar(start = pi/2) + 
  scale_x_continuous(limits = c(0, nrow(df)*2)) + 
  geom_text(aes(label=scales::percent(y))) + 
  ggthemes::theme_map() + theme(legend.position = c(0,.15))

gives you

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100