简体   繁体   中英

R: Change number of ticks in ggplot2 with ggthemes::extended_range_breaks()

assume the following 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. Anyone an idea how to do that when working with extended_range_breaks or do I have to switch to manually setting the ticks?

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.

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. If we set coverage for example to 2 (for the y-axis), the graph changes to the following:

在此处输入图像描述

The actual desired goal to simly add (-2,2) was yet not possible with this tweak.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM