Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

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))

enter image description here

Desired chart:

enter image description here

1 Answer

0 votes
by

To remove the x-axis labels, text, and ticks, add the following function to your plot:

theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank())

Here element_blank() is used inside theme() function to hide the axis labels, text, and ticks.

In your case:

ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut))+ theme_bw()+ theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank())

Output:

image

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...