I get an error that seems to be combined by using annotation_logticks()
and coord_flip()
on the same plot. For instance:
ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_line() +
annotation_logticks(sides="l") +
coord_flip()
gives the error Error in unit(yticks$y, "native") : 'x' and 'units' must have length > 0
. traceback()
gives results that I don't totally understand, but which seem to have something to do with assigning units.
On the other hand, annotation_logticks()
or coord_flip()
alone doesn't cause any problem.
ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_line() +
annotation_logticks(sides="l") #+
#coord_flip()
works fine, as does
ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_line() +
#annotation_logticks(sides="l") #+
coord_flip()
I could switch the x
and y
mappings to avoid coord_flip()
, but this is not ideal (I have to rewrite old plots if I want to add annotation_logticks()
for instance).
This has now been fixed in ggplot2 version 3.3.4 by this PR.
library(ggplot2)
ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_line() +
annotation_logticks(sides="l") +
coord_flip()
Created on 2021-08-29 by the reprex package (v2.0.0)
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