在ggplot中设置上限以包括大于最大值的标签 [英] set upper limit in ggplot to include label greater than the maximum value
问题描述
我的数据范围似乎总是大于y轴上的顶部标签。有没有一种方法可以自动包含它,而无需手动设置限制?
例如。 in
ggplot(data.frame(x = 1:11,y = c(11:17,5:2)) ,aes(x,y))+ geom_point()
我想要标签0和20出现在y轴上,o和12出现在x轴上(并且该图相应地展开)。例如,这应该是自动完成的,而不用在比例选项中指定这些数字。
如何解决以下问题:
pre $ library(ggplot2)
d < - data.frame(x = 1:11,y = c(11:17,5: 2))
px< - pretty(d $ x)
py< - 漂亮(d $ y)
ggplot(d,aes(x,y)) + geom_point()+
scale_x_continuous(breaks = px,limits = range(px))+
scale_y_continuous(breaks = py,limits = range(px))
My data range always seems to be greater than the top label in the y-axis. Is there a way I can automatically include it without manually setting limits?
e.g. in
ggplot(data.frame(x=1:11, y=c(11:17,5:2)), aes(x,y)) + geom_point()
I would like to have labels 0 and 20 appear on the y-axis and o and 12 appear on the x-axis (and the plot expand accordingly). This should be done automatically without specifying these numbers in scale options for example.
What about the following solution:
library(ggplot2)
d <- data.frame(x=1:11, y=c(11:17,5:2))
px <- pretty(d$x)
py <- pretty(d$y)
ggplot(d, aes(x,y)) + geom_point() +
scale_x_continuous(breaks=px, limits=range(px)) +
scale_y_continuous(breaks=py, limits=range(px))
这篇关于在ggplot中设置上限以包括大于最大值的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!