I have seen both usages, yet I don't know the difference between 2 in practical.
And, why
stat_vline(xintercept="mean", geom="vline") # this works
But
geom_vline(xintercept="mean", stat="vline") # this doesn't work
Does that mean after passing mean
to a next layer which is vline
in this case, the function becomes character? Is this behaviour general?
By default, geom_bar uses stat="bin". This makes the height of each bar equal to the number of cases in each group, and it is incompatible with mapping values to the y aesthetic. If you want the heights of the bars to represent values in the data, use stat="identity" and map a value to the y aesthetic."
If it is stat = "identity" , we are asking R to use the y-value we provide for the dependent variable. If we specify stat = "count" or leave geom_bar() blank, R will count the number of observations based on the x-variable groupings.
For this, we have to specify three arguments within the geom_bar function: position = “dodge” stat = “summary” fun = “mean”
Using the geom_bar (position="dodge") places the two bars side by side.
You might have found a bug. If you specify the aesthetics mapping (again) it works:
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
p + geom_vline(aes(x=wt, y=mpg), xintercept="mean", stat="vline")
Typical for ggplot2
documentation is somewhat sparse, which makes it difficult to judge if this is intentional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With