How to remove y-axis labels in ggplot
To remove y-axis labels in a ggplot chart, you can use the element_blank()
function for the axis.text.y
parameter. Here’s an example code:
library(ggplot2)
# create example data
df <- data.frame(x = 1:10, y = rnorm(10))
# create ggplot chart
ggplot(df, aes(x, y)) +
geom_point() +
theme(axis.text.y = element_blank())
This will remove the y-axis labels, but keep the y-axis line and ticks. If you also want to remove the ticks, you can use the element_blank()
function for the axis.ticks.y
parameter:
ggplot(df, aes(x, y)) +
geom_point() +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
This will remove both the y-axis labels and ticks.