• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

Remove Axis Text & Ticks in ggplot2 (R) — Quick Examples

datavizpyr · January 31, 2020 ·

Last updated on August 22, 2025

Sometimes when making a plot in R, you may want a cleaner chart without axis labels or tick marks. In ggplot2, both axis text (the labels) and axis ticks (the small tick marks) can be removed or customized. In this tutorial, you’ll learn how to remove axis text and ticks in ggplot2 for the x-axis and y-axis using theme() and element_blank(). Examples cover heatmaps and quick variations you can reuse in other charts.

👉 Want more? See the complete ggplot2 Tutorial Hub with 35+ recipes.

Load Packages

Let us first load tidyverse, a suite of R packages from RStudio. Let us also load gapminder R package as we will be using gapminder data to make the plot with x-axis ticks and text.

library(tidyverse)
library(gapminder)
theme_set(theme_bw(base_size=16))

Example Data

We’ll use a subset of the gapminder dataset for African countries and convert the year variable into a factor:

df1 <- gapminder |>
  filter(continent %in% c("Africa")) |>
  mutate(year=factor(year))

Example Plot With Axis Text and Ticks

Our example plot in this post is a heatmap of lifeExp over years for african countries. We can make heatmap from tidy data using ggplot2’s geom_tile() function. We have country on y-axis and year on x-axis and the values of heatmap are lifeExp.

df1 |>
  ggplot(aes(y=country, x=year, fill=lifeExp)) + 
  geom_tile() +
  scale_fill_viridis_c()

This default heatmap includes axis ticks (small black lines) and axis text labels (years on the x-axis, countries on the y-axis).

A plot with Axis Tick and Axis Text in ggplot2
A plot with Axis Tick and Axis Text in ggplot2

Remove Axis Text and Ticks in ggplot2

The theme() function lets us control axis appearance:

  • Remove x-axis ticks: axis.ticks.x = element_blank()
  • Remove x-axis text: axis.text.x = element_blank()

We can remove axis ticks and texts using the theme function in ggplot2. The theme() function in ggplot2 is a powerful function that allows users to customize various aspects of ggplot2 theme including the axis ticks and texts.

To remove x-axis ticks we specify the argument axis.ticks.x = element_blank() inside the theme(). And similarly to remove x-axis text, we specify axis.text.x = element_blank().

df1 |>
  ggplot(aes(y=country, x=year, fill=lifeExp)) + 
  geom_tile() +
  scale_fill_viridis_c() + 
  theme(axis.ticks.x = element_blank(),
        axis.text.x = element_blank())

You can also remove the y-axis text and ticks using axis.ticks.y and axis.text.

A plot without x-axis tick and x-axis Text in ggplot2
Remove x-axis tick and x-axis Text in ggplot2

More Variations

Remove only axis ticks, keep text

p <- df1 |>
  ggplot(aes(y=country, x=year, fill=lifeExp)) + 
  geom_tile() +
  scale_fill_viridis_c()

p + theme(axis.ticks = element_blank())

Remove all axis text and ticks (both x and y)

p + 
  labs(title="Remove all axis text and ticks (both x and y axis)") +
  theme(
  axis.text  = element_blank(),
  axis.ticks = element_blank()
)
ggsave("Remove_all_axis_text_and_ticks_both_x_and_y_ggplot.png")
Remove all axis text and ticks (both x and y)
Remove all axis text and ticks (both x and y) with axis.text and axis.ticks

Remove axis titles but keep tick labels

p + theme(axis.title = element_blank())

FAQs

How do I remove only the x-axis labels in ggplot2?

Use axis.text.x = element_blank() inside theme().

What’s the difference between axis.text and axis.title?

axis.text controls tick labels; axis.title controls the axis title (e.g., “Year”). They’re independent.

How do I remove ticks but keep labels?

Use axis.ticks = element_blank() and leave axis.text unchanged.

Related Tutorials

  • ggplot2 Hub — 35+ tutorials
  • Heatmaps with ggplot2

Reference: ggplot2 theme() docs

Related posts:

Dollar format ggplot2How to Add Dollar Symbol for Axis Labels with ggplot2? Customizing Labels on Bars in Side by side Stacked BarplotHow To Add Labels to Grouped Barplot with Bars Side-By-Side in R? Visualizing Missing Data with Barplot in R ggplot2Visualizing Missing Data with Barplot in R Annotate Clusters with Ellipse with Labels ggforceHow To Annotate Clusters with Circle/Ellipse by a Variable in R

Filed Under: ggplot2, R, remove axis tick and text Tagged With: ggplot2, R

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

Copyright © 2026 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version