增加轴刻度数 [英] Increase number of axis ticks
问题描述
我正在为一些数据生成图表,但刻度数太少,我需要更高的精度读数.
I'm generating plots for some data, but the number of ticks is too small, I need more precision on the reading.
有什么方法可以增加 ggplot2 中的轴刻度数吗?
Is there some way to increase the number of axis ticks in ggplot2?
我知道我可以告诉 ggplot 使用向量作为轴刻度,但我想要的是增加所有数据的刻度数.换句话说,我希望根据数据计算刻度数.
I know I can tell ggplot to use a vector as axis ticks, but what I want is to increase the number of ticks, for all data. In other words, I want the tick number to be calculated from the data.
可能 ggplot 使用某种算法在内部执行此操作,但我找不到它是如何执行的,根据我的需要进行更改.
Possibly ggplot do this internally with some algorithm, but I couldn't find how it does it, to change according to what I want.
推荐答案
您可以通过修改 scale_x_continuous
和/或 scale_y_continuous
来覆盖 ggplots 默认比例.例如:
You can override ggplots default scales by modifying scale_x_continuous
and/or scale_y_continuous
. For example:
library(ggplot2)
dat <- data.frame(x = rnorm(100), y = rnorm(100))
ggplot(dat, aes(x,y)) +
geom_point()
给你这个:
覆盖比例可以给你这样的东西:
And overriding the scales can give you something like this:
ggplot(dat, aes(x,y)) +
geom_point() +
scale_x_continuous(breaks = round(seq(min(dat$x), max(dat$x), by = 0.5),1)) +
scale_y_continuous(breaks = round(seq(min(dat$y), max(dat$y), by = 0.5),1))
如果您只想放大"绘图的特定部分,请分别查看 xlim()
和 ylim()
.也可以在此处找到很好的见解,以了解其他论点.
If you want to simply "zoom" in on a specific part of a plot, look at xlim()
and ylim()
respectively. Good insight can also be found here to understand the other arguments as well.
这篇关于增加轴刻度数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!