I have data with x-values ββon a scale from 0 to 100, for example:
library(ggplot2)
set.seed(42)
df <- data.frame(x=c(rep(100, 20), runif(100, min=0, max=100)),
y=rnorm(120, mean=4, sd=2))
A simple scatter chart created by this code:
ggplot(df, aes(x=x, y=y)) +
geom_point(size=5) +
theme(panel.grid.major=element_line(color='black'),
panel.grid.minor=element_line(color='black'),
panel.background=element_rect(fill='white'))
looks like that:

But in order to emphasize that values ββof x outside the range from 0 to 100 do not make sense, I want to copy the x axis and horizontal grid lines exactly at x = 0 and x = 100. I was given to understand that the correct way to do this is with expandby adding scale_x_continuous(limits=c(0, 100), expand=c(0, 0))to my object ggplot. Result:
This shortens the grid lines, but also copies the scatter plot markers on the left and right edges, as well as on the label 100 along the x axis. Can I cut only along the x axis and the grid line in front of the edge, but make the markers and marks of the axes as if the margin is still there?