Reputation: 1
Code giving error: ggplot(mtcars, aes(wt, mpg)) + geom_point(aes(shape = 1, size = 4))
Code Not giving error: ggplot(mtcars, aes(wt, mpg)) + geom_point(shape = 1, size = 4)
Upvotes: 0
Views: 71
Reputation: 12451
It's not a question of timing. It's a question of default behaviour.
The actual error message is
Error: A continuous variable can not be mapped to shape
So in the first example, because shape
is inside the call to aes()
, it is defining a scale. 1
is regarded not as a constant but as a continuous variable.
In the second example, because shape is outside the call to aes()
, it does not define a scale and therefore the error does not occur.
A variation of the first example which does not produce an error is
gplot(mtcars, aes(wt, mpg)) + geom_point(aes(shape = as.factor(1), size = 4))
because the call to as.factor()
means that 1
is no longer regarded as continuous.
Upvotes: 1