I'm generating a plot and I am trying to figure out how to suppress just one tick-mark label (not the mark -- just the label).
Here's some example code:
x1 <- seq(0, 100, by = 1)
y1 <- runif(n = 100, min = 1, max = 10)
library(rando)
labe <- r_Letters(nchar = 1, n = 100)
test_dat <- as.data.frame(cbind(x1, y1, labe))
test_dat$x1 <- as.numeric(test_dat$x1)
test_dat$y1 <- as.numeric(test_dat$y1)
library(ggplot2)
library(ggrepel)
g <- ggplot(data = test_dat, aes(x = x1, y = y1))
g <- g + geom_line()
g <- g + geom_point()
g <- g + expand_limits(x = c(-10, 110), y = c(0, 10))
g <- g + scale_x_continuous(breaks = scales::pretty_breaks(n = 25))
g <- g + scale_y_continuous(breaks = scales::pretty_breaks(n = 5))
g <- g + geom_label_repel(data = test_dat, aes(x = x1, y = y1, label = labe),
size = 2.0, color = "blue", box.padding = unit(0.5, "lines"),
point.padding = unit(0, "lines"))
g
In my real dataset, when I use geom_label_repel to label my points (a subset of my real data; I got lazy in my example), I needed to extend the range of the plot (hence, expand_limits). All of the tick marks are where I'd like them, but the one on the far left (-15 in my example) is unphysical and I'd like to remove just that one.
I can figure out how to suppress all the tick marks and all the labels, but that's not what I'm after -- I want to leave the tick marks as they are, but just remove the label on the one that's furthest left.
Any thoughts?
One approach could be to manually adjust your break labels using a formula that outputs a blank at the -15 label, but otherwise leaves it alone.
g <- g + scale_x_continuous(breaks = scales::pretty_breaks(n = 25),
labels = ~if_else(.x == -15, "", as.character(.x)))