[英]How do I set breaks when using a percentage scale on ggplot2?
I'm trying to manually enter when the breaks on the axis labels should be for my graph -- ie every 10 percentage points, every 25, etc, instead of having ggplot calculate them automatically. 我试图手动输入何时轴标签上的中断应该适合我的图形-即每10个百分点,每25个百分点等,而不是让ggplot自动计算它们。
ggplot(cars, aes(x=speed)) +
geom_histogram(binwidth=.1, colour="white", fill="dark green", aes(y = (..count..)/sum(..count..))) +
scale_x_continuous(labels=percent) +
scale_y_continuous(labels=percent)
This is sort of random data, but shows the basic idea -- I would like to be able to set these in the: 这是一种随机数据,但显示了基本思想-我希望能够在以下位置进行设置:
scale_x_continuous(labels=percent)
in the same way as one can write that there should be breaks every x units using this code: 就像可以写成这样,使用此代码每个x单位都应有中断:
scale_x_continuous(breaks=seq(0,2, by=.1))
Does anyone have suggestions? 有人有建议吗?
The breaks
argument and the labels
argument are not exclusive. breaks
参数和labels
参数不是唯一的。 The former is for determining where the breaks should be and the latter is for how they should be formatted/displayed. 前者用于确定换行符应位于何处,而后者用于确定换行符的格式/显示方式。 Thus you can do
这样你就可以做
scale_x_continuous(breaks = seq(0, 2, by = 0.1), labels = percent)
to specify both aspects. 同时说明这两个方面。
Something like: 就像是:
ggplot(cars, aes(x=speed)) +
geom_histogram(binwidth=.1, colour="white", fill="dark green", aes(y = (..count..)/sum(..count..))) +
scale_x_continuous(breaks= seq(0,1,.1)*max(cars$speed), labels = seq(0,100,10)) + labs(x = "speed (%)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.