我试图在绘图中一起使用xlim和scale_x_reverse,例如:
p <- ggplot(mtcars, aes(x = wt, y=mpg), . ~ cyl) + geom_point()
p + geom_line() +
xlim(2, 5) +
scale_x_reverse()
两个命令都独立工作,但不能一起工作。相反,我得到:
Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.
有没有办法同时上班?
谢谢,
锤
答案 0 :(得分:4)
p + geom_line() +
scale_x_reverse(limits = c(5, 2))
#Warning messages:
#1: Removed 7 rows containing missing values (geom_point).
#2: Removed 7 rows containing missing values (geom_path).
p + geom_line() +
scale_x_reverse() +
coord_cartesian(xlim = c(5, 2))
答案 1 :(得分:0)
按照BondedDust的建议使用+ xlim(5,2)。
p <- ggplot(mtcars, aes(x = wt, y=mpg), . ~ cyl) + geom_point()
p + geom_line() +
xlim(5, 2)