1

I came across the question of Brandon Bertelesen because I had the same problem. However, even his MWE does not work with me; I either get:

Error: stat_count() must not be used with a y aesthetic

when I include geom_bar()

or

Error in scale_y_continuous("", formatter = "percent") : unused argument (formatter = "percent")`

when I include scale_y_continuous("",formatter="percent")

but not geom_bar()

Can someone explain me what I did wrong? And maybe post an updated answer to the original question?

neilfws
  • 32,751
  • 5
  • 50
  • 63
Lukas
  • 424
  • 3
  • 6
  • 17

1 Answers1

0

Here is an updated version of the code from that question

library(ggplot2)
library(scales)
ggplot(x, aes(x = variable, y = value)) + 
geom_bar(stat = "identity") +
scale_y_continuous(labels = scales::percent) + 
coord_flip() 

I guess back then the default stat in geom_bar was "identity", now it is "count". scale_y_continuous does not have the argument formatter anymore.

DATA

x <- structure(list(variable = structure(c(10L, 6L, 3L, 4L, 2L, 8L, 
9L, 5L, 1L, 7L), .Label = c("a", "b", "c", "d", "e", "f", "g", 
"h", "i", "j"), class = c("ordered", "factor")), value = c(0.990683229813665, 
0.975155279503106, 0.928571428571429, 0.807453416149068, 0.717391304347826, 
0.388198757763975, 0.357142857142857, 0.201863354037267, 0.173913043478261, 
0.0496894409937888)), .Names = c("variable", "value"), row.names = c(10L, 
6L, 3L, 4L, 2L, 8L, 9L, 5L, 1L, 7L), class = "data.frame")
markus
  • 25,843
  • 5
  • 39
  • 58