how to remove an xlab in ggplot in r

To remove the x-axis label in ggplot2, you can use the following code:

main.r
library(ggplot2)

# Create a plot
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point()

# Remove the x-axis label
p + 
  labs(x = NULL)
142 chars
10 lines

Alternatively, you can also use the element_blank() function to remove the x-axis label:

main.r
p + 
  theme(axis.title.x = element_blank())
45 chars
3 lines

Both of these methods will remove the x-axis label from your ggplot.

related categories

gistlibby LogSnag