在 ggplot2 轴上有限制的标准中断
Standard breaks with limits in ggplot2 axis
我想要的很简单,但很难实现:在 ggplot2()
会设置它们的地方设置刻度,另外在极限处。因为我要处理很多数据集,所以我想避免自己设置刻度。
require(ggplot2)
ggplot(data=ChickWeight, aes(ChickWeight$Time)) geom_histogram(binwidth=1)
为了给坐标轴加上max(ChickWeight$Time)
,我试过pretty()
,超出了最大值:
ggplot(data=ChickWeight, aes(ChickWeight$Time)) + geom_histogram(binwidth=1)
+ scale_x_continuous(breaks=pretty(ChickWeight$Time))
...以及 pretty_breaks()
,这使得中断更少:
require(scales)
ggplot(data=ChickWeight, aes(ChickWeight$Time)) + geom_histogram(binwidth=1)
+ scale_x_continuous(breaks=pretty_breaks(ChickWeight$Time))
但是 none 的解决方案采用任何看起来像最大值的参数。然而,我的最大值有些特别,这就是为什么我想将它包含在情节中。
一个解决方案是将 pretty()
和 max()
组合为 breaks=
值以在最大 value.If 处设置额外的刻度函数 pretty()
将产生值由于子集化,那些大于最大值的值将不会显示。
ggplot(data=ChickWeight, aes(Time)) + geom_histogram(binwidth=1)+
scale_x_continuous(breaks=c(pretty(ChickWeight$Time)[pretty(ChickWeight$Time)<max(ChickWeight$Time)],max(ChickWeight$Time)))
我想要的很简单,但很难实现:在 ggplot2()
会设置它们的地方设置刻度,另外在极限处。因为我要处理很多数据集,所以我想避免自己设置刻度。
require(ggplot2)
ggplot(data=ChickWeight, aes(ChickWeight$Time)) geom_histogram(binwidth=1)
为了给坐标轴加上max(ChickWeight$Time)
,我试过pretty()
,超出了最大值:
ggplot(data=ChickWeight, aes(ChickWeight$Time)) + geom_histogram(binwidth=1)
+ scale_x_continuous(breaks=pretty(ChickWeight$Time))
...以及 pretty_breaks()
,这使得中断更少:
require(scales)
ggplot(data=ChickWeight, aes(ChickWeight$Time)) + geom_histogram(binwidth=1)
+ scale_x_continuous(breaks=pretty_breaks(ChickWeight$Time))
但是 none 的解决方案采用任何看起来像最大值的参数。然而,我的最大值有些特别,这就是为什么我想将它包含在情节中。
一个解决方案是将 pretty()
和 max()
组合为 breaks=
值以在最大 value.If 处设置额外的刻度函数 pretty()
将产生值由于子集化,那些大于最大值的值将不会显示。
ggplot(data=ChickWeight, aes(Time)) + geom_histogram(binwidth=1)+
scale_x_continuous(breaks=c(pretty(ChickWeight$Time)[pretty(ChickWeight$Time)<max(ChickWeight$Time)],max(ChickWeight$Time)))