Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Why is stat = "identity" necessary in geom_bar in ggplot?

$
0
0

From this question we see a simple geom_line in the answer.

library(dplyr)
BactData %>% filter(year(Date) == 2017) %>% 
  ggplot(aes(Date, Svartediket_CB )) + geom_line()

If we change geom_line to geom_bar we may expect to see a bar plot, but instead

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

But it works if we add stat = "identity", like so

library(dplyr)
BactData %>% filter(year(Date) == 2017) %>% 
  ggplot(aes(Date, Svartediket_CB )) + geom_bar(stat = "identity")

Why doesn't geom_bar work without stat = "identity" - i.e. what is the purpose of stat = "identity"?


Viewing all articles
Browse latest Browse all 201839

Trending Articles