2
votes

I have a chart and need to expand the x-axis scale to accommodate labels which go past my maximum value (1 as the x-axis represents a percentage).

I am able to do this using the limits argument in scale_x_continuous, but I still can see the associated gridlines at 1.1. Is there any way to remove just this gridline (bordered by the red box in the image below), but keep the expanded plot?

library(dplyr)
library(ggplot2)

data.frame(val1 = seq(0, 1, 0.1),
           val2 = seq(0, 1, 0.1)) %>% 
  ggplot(aes(x = val1, y = val2)) +
  scale_x_continuous(limits = c(0, 1.05),
                     breaks = seq(0, 1, 0.1))

enter image description here

1

1 Answers

4
votes

This could be achieved by setting restricting the range of the minor breaks too:

library(dplyr)
library(ggplot2)

data.frame(val1 = seq(0, 1, 0.1),
           val2 = seq(0, 1, 0.1)) %>% 
  ggplot(aes(x = val1, y = val2)) +
  scale_x_continuous(limits = c(0, 1.05),
                     breaks = seq(0, 1, 0.1),
                     minor_breaks = seq(0, 1, 0.05))

Created on 2021-06-07 by the reprex package (v2.0.0)