[英]R: Change number of ticks in ggplot2 with ggthemes::extended_range_breaks()
assume the following MWE:假设以下 MWE:
library(ggplot2)
library(ggthemes)
set.seed(100)
df <- data.frame(x = rnorm(50), y = rnorm(50))
ggplot(df, aes(x,y)) +
geom_point() +
theme_tufte() +
geom_rangeframe() +
scale_x_continuous(breaks = extended_range_breaks()(df$x),
labels = scales::number_format(accuracy = 0.1))+
scale_y_continuous(breaks = extended_range_breaks()(df$y),
labels = scales::number_format(accuracy = 0.1))
From my point of view the number of ticks on the y-axis is not enough, the space between 1.0 and 2.9 is too large and I would like to have another tick at 2.0.从我的角度来看,y 轴上的刻度数不够,1.0 和 2.9 之间的空间太大,我想在 2.0 再有一个刻度。 Anyone an idea how to do that when working with extended_range_breaks or do I have to switch to manually setting the ticks?任何人都知道在使用 extended_range_breaks 时如何做到这一点,或者我是否必须切换到手动设置刻度?
I tried scale_y_continuous(n.breaks = 7)
and scale_y_continuous(breaks = extended_range_breaks(n = 7)(df$y)
but both don't have an effect.我试过scale_y_continuous(n.breaks = 7)
和scale_y_continuous(breaks = extended_range_breaks(n = 7)(df$y)
但两者都没有效果。
Not a perfect answer, but at least a work-around for now: change the weights applied to the four optimization components.不是一个完美的答案,但至少现在是一种解决方法:更改应用于四个优化组件的权重。 The parameters are set to w = c(0.25, 0.2, 0.5, 0.05)
for simplicity, coverage, density, and legibility.为了简单、覆盖、密度和易读性,参数设置为w = c(0.25, 0.2, 0.5, 0.05)
。 If we set coverage for example to 2 (for the y-axis), the graph changes to the following:例如,如果我们将覆盖率设置为 2(对于 y 轴),则图表将变为以下内容:
The actual desired goal to simly add (-2,2)
was yet not possible with this tweak.通过这个调整,实际想要的简单添加(-2,2)
的目标是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.