ggplot2轴:如何将scale_x_reverse与scale_x_continous组合 [英] ggplot2 axis: how to combine scale_x_reverse with scale_x_continous
问题描述
对于我的图表
ggplot(data=data, x=x, y=y, fill=factor(c)+ geom_path()+geom_errorbar()+ geom_point()
我想使用
scale_y_reverse()
在定义其限制,中断,标记和扩展时.
while define its limits, breaks, labels and expands.
我通常使用:
scale_y_continuous(limits=c(x,y), breaks=c(x,y,z), labels=c(x,y,z), expand(x,y))
好吧,显然
scale_y_reverse()
和scale_y_continous()被认为是相同的代码!当我收到一个错误消息时,说:
and scale_y_continous() are somehow considered as the same code!? As I get an Error, saying:
"y的比例已存在.为y添加另一个比例,它将替换现有规模."
"Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale."
我发现一则帖子说可以合并这两个命令,因此我尝试了:
I found a post saying that it is possible to combine the two commands, thus I tried:
scale_y_reverse(limits=c(x,y), breaks=c(x,y,z), labels=c(x,y,z), expand(x,y))
也不起作用.
我确信必须有一种方法,并且像往常一样,我想这很简单..一旦您知道.
I am sure that there has to be a way, and as usual I suppose it is very simple.. once you know.
我希望有人知道如何解决这个问题.
I hope someone know how to solve this.
亲切的问候
推荐答案
图形的每个美学属性(y轴,x轴,颜色等)仅接受一个比例.如果您指定2个比例,例如 scale_y_continuous()
后跟 scale_y_reverse()
,第一个比例尺将被覆盖.
Each aesthetic property of the graph (y-axis, x-axis, color, etc.) only accepts a single scale. If you specify 2 scales, e.g. scale_y_continuous()
followed by scale_y_reverse()
, the first scale is overridden.
您可以在 scale_y_reverse()
中指定限制,中断和标签,而只需省略 scale_y_continuous()
.
You can specify limits, breaks, and labels in scale_y_reverse()
and just omit scale_y_continuous()
.
示例:
d <- data.frame(a = 1:10, b = 10:1)
ggplot(d, aes(x = a, y = b)) +
geom_point() +
scale_y_reverse(
limits = c(15, 0),
breaks = seq(15, 0, by = -3),
labels = c("hi", "there", "nice", "to", "meet", "you")
)
这篇关于ggplot2轴:如何将scale_x_reverse与scale_x_continous组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!