328

I need to remove everything on the x-axis including the labels and tick marks so that only the y-axis is labeled. How would I do this?

In the image below I would like 'clarity' and all of the tick marks and labels removed so that just the axis line is there.

Sample ggplot

data(diamonds)
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))

ggplot Chart:

enter image description here

Desired chart:

enter image description here

Vedda
  • 7,066
  • 6
  • 42
  • 77

1 Answers1

716

You have to set to element_blank() in theme() elements you need to remove

ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201
  • 19
    Is there a way to just get rid of the entire axis, like `axes = FALSE` in base R. This is a lot of work. – jtr13 Oct 05 '18 at 19:31
  • 37
    @jtr13, you can use theme_void() to get rid of everything: `ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + theme_void()` – Augusto Fadel Jan 03 '19 at 17:36
  • Reference: [ggplot doc](http://www.sthda.com/english/wiki/ggplot2-title-main-axis-and-legend-titles) – Andry May 23 '20 at 11:22
  • 30
    There is a very 'ggplot' way of doing it using `scale_x_discrete` and `labs`: `ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + scale_x_discrete(labels = NULL, breaks = NULL) + labs(x = "")` – Will Pike Feb 19 '21 at 01:26
  • 6
    @WillPike +1. A slight tweak is to use `labs(x = NULL)` to completely remove the margin used for the label. – Breaking Waves Sep 27 '22 at 18:04