• 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
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to change axis tick label size in ggplot2

datavizpyr · September 21, 2024 ·

In this post we will learn how to change axis tick label size in ggplot2 with multiple example. When we make a plot with ggplot2, plots have axis ticks- small vertical bars on both x and y axis, and tick labels – right below the ticks.

change axis tick label size ggplot2
change axis tick label size ggplot2

We can change the size of axis tick labels in ggplot2 using theme() function in combination with element_text() function.

library(tidyverse)
library(palmerpenguins)
theme_set(theme_bw(16))

Let us make a scatter plot with default axis tick label size. In this example below, the size of axis tick label is fixed by our theme_bw(16) setting upfront.

penguins |>
  ggplot(aes(body_mass_g, bill_length_mm, color=species))+
  geom_point()+
  labs(title="How to change axis tick label size in ggplot2")
ggsave("how_to_change_axis_tick_label_size_ggplot2.png")
How to change axis tick label size in ggplot2
How to change axis tick label size in ggplot2

Change axis text label size using axis.text argument to theme() function

We can change axis text label size using theme() function by providing the argument axis.text to modify axis text label properties of both x and y axes. With size argument to element_text(), we can change the size of the axis tick labels.

penguins |>
  ggplot(aes(body_mass_g, bill_length_mm, color=species))+
  geom_point()+
  labs(title=stringr::str_wrap("Change axis tick label size in ggplot2 with element_text()", width=40)) +
  theme(axis.text = element_text(size=24))
ggsave("change_axis_tick_label_size_ggplot2_using_theme.png")
Changing axis tick label size (both x & y) in ggplot2 with theme() and element_text()
Changing axis tick label size (both x & y) in ggplot2 with theme() and element_text()

Change x-axis text label size using axis.text argument to theme() function

If needed, we can also selectively change either x or y axis text label size using the same approach used above. In the example, we are changing the size of x-axis tick labels alone using axis.text.x argument to theme() function.

penguins |>
  ggplot(aes(body_mass_g, bill_length_mm, color=species))+
  geom_point()+
  labs(title=stringr::str_wrap("Change x-axis tick label size in ggplot2 with element_text()", width=40)) +
  theme(axis.text.x= element_text(size=24))
ggsave("change_x_axis_tick_label_size_ggplot2_using_theme.png")
Change x-axis tick label size in ggplot2 with theme() and  element_text()
Change x-axis tick label size in ggplot2 with theme() and element_text()

Change y-axis text label size using axis.text argument to theme() function

Here we show how to changing the size of y-axis tick labels alone using axis.text.y argument to theme() function.

penguins |>
  ggplot(aes(body_mass_g, bill_length_mm, color=species))+
  geom_point()+
  labs(title=stringr::str_wrap("Change y-axis tick label size in ggplot2 with element_text()", width=40)) +
  theme(axis.text.y = element_text(size=24))
ggsave("change_y_axis_tick_label_size_ggplot2_using_theme.png")
Change y-axis tick label size in ggplot2 with theme() and  element_text()
Change y-axis tick label size in ggplot2 with theme() and element_text()

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? Default Thumbnail4 Ways to have Plots Side by side in ggplot2 Default ThumbnailHow to make rolling mean line plot of stock data

Filed Under: ggplot2, ggplot2 element_text(), R Tagged With: change axis tick label size ggplot2

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

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

Go to mobile version