rggplot2ggthemes

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))

enter image description here

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.


Solution

  • 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:

    enter image description here

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