Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between `geom_a(stat="b", ...)` and `stat_b(geom="a",...)`?

Tags:

r

ggplot2

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?

like image 929
colinfang Avatar asked Sep 13 '13 12:09

colinfang


People also ask

What is the difference between using Geom_bar () and Geom_bar Stat identity )?

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."

What is the difference between stat identity and stat count?

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.

What does stat mean in Geom_bar?

For this, we have to specify three arguments within the geom_bar function: position = “dodge” stat = “summary” fun = “mean”

What is Dodge in Geom_bar?

Using the geom_bar (position="dodge") places the two bars side by side.


1 Answers

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.

like image 80
Roland Avatar answered Oct 12 '22 11:10

Roland