Allow `int` field on `aes(x = ...)`
TimSoethout opened this issue · comments
I am running into a problem where my aes(x = ...)
value is an int
.
The error is:
Error in eval(substitute(list(...)), `_data`, parent.frame()) :
object 'x' not found
I did find out that after converting the field to str
(with data$n <- as.character(data$n)
) it suddenly works, but now my axis is sorted by the string values instead of the ints.
Is there any way to solve this?
The same happens on this example:
> ggplot(mpg, aes(x = cyl, y = cty)) + geom_pirate(aes(colour = cyl, fill = cyl))
Error in eval(substitute(list(...)), `_data`, parent.frame()) :
object 'x' not found
This works:
> mgp <- mpg
> mgp$cyl <- as.character(mgp$cyl)
> ggplot(mgp, aes(x = cyl, y = cty)) + geom_pirate(aes(colour = cyl, fill = cyl))
Although because there are no numbers > 9, the sorting problem does not occur. (In string land 2 > 10)
as.factor
instead of as.character
seems to keep the correct order (although my dataset itself was already ordered)
Related to this: I want to create a plot with pirate plots for x value which is an integer, and then plot some fitted line over it.
Unfortunately this is not possible now because ggpirate only supports discrete values.
ggpirate only supports discrete x scales, just like bar plots themselves. I would recommend setting the desired order for your variable with a factor, as you suggested.