2
$\begingroup$

Why are the percentages in the y-axis of this bar chart displayed incorrectly (values larger than 100%) and how can I fix it?

qplot(tctype,tccount,data=categ,xlab="Type",ylab="",geom = "bar")+ scale_y_continuous(formatter="percent")

enter image description here

This is the data frame

categ
                  tctype tccount
1  inthread (10 or less)   16228
2 occasional (10 to 100)    3561
3 addicted (100 to 1000)     327
4        communal(1000+)      10
$\endgroup$
3
  • 3
    $\begingroup$ Maybe try qplot(tctype,tccount/sum(tccount),data=categ,xlab="Type",ylab="",geom = "bar")+ scale_y_continuous(formatter="percent") $\endgroup$
    – mark999
    Jun 18, 2011 at 6:35
  • 3
    $\begingroup$ It's displaying it correctly, 16228 = 1622800%, you'll have to normalize the data yourself as suggested. $\endgroup$
    – nico
    Jun 18, 2011 at 8:06
  • $\begingroup$ I see, I thought the formatter part would do it automatically. This is exactly what I needed. Thanks a lot! $\endgroup$
    – amh
    Jun 19, 2011 at 16:46

1 Answer 1

1
$\begingroup$

As mark999 mentioned in the comment above, I needed to normalize the data like this:

plot(tctype,tccount/sum(tccount),data=categ,xlab="Type",ylab="",geom = "bar")+ scale_y_continuous(formatter="percent") 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.