Here is a MWE:
library(ggplot2)
library(ggridges)
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=..x..)) +
geom_density_ridges_gradient()
My query is : can we not say fill = Sepal.Length
?
I understand that ..x..
refers to a computed variable x
and the call to geom_density_ridges_gradient
will probably not see the variable in the ggplot terminology, but at the time of the ggplot incantation we CAN refer to Sepal.Length
, can we?
Can someone please clarify why we need to say ..x..
and not Sepal.Length
in this case? I am not fully certain of the reasoning here.
To be more precise why does this not work:
ggplot(iris, aes(x=Sepal.Length, y=Species,
fill=Sepal.Length)) + geom_density_ridges_gradient()
<------------I would like to rephrase my query starting here------------>
If I do :
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges_gradient(fill = Sepal.Length)
geom_density_ridges_gradient will not be able to find the variable Sepal.Length and it gives an error.
So, the right incantation should be:
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges_gradient(fill = ..x..)
geom_density_ridges_gradient should be able to find the computed variable ..x.. , but it does NOT work. Can someone please explain why this is ?
Another query:
If I do :
ggplot(iris, aes(x = Sepal.Length, y = Species,fill = Sepal.Length)) +
geom_density_ridges_gradient()
Why does it not give me an error message saying Sepal.Length not found,
it simply ignores the fill argument and draws the output,why is this ?
What finally seems to work is this :
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=..x..)) +
geom_density_ridges_gradient()
but I am not sure why is it that it works.
Basically I am confused as to where the argument corresponding to the fill should be placed.