• 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 Font Size with ggplot2 in R?

datavizpyr · December 13, 2019 ·

A plot or graphics made without legible x-axis and y-axis labels is a worthless plot. ggplot2 in R makes it easy to change the font size of axis labels.

In this post, we will see examples of how to increase the font size of x and y-axis labels in R, including the tick mark labels and axis description labels, using ggplot2.

Let us first load tidyverse.

library(tidyverse)

We will use the faithful data set that is inbuilt in R.

head(faithful)

faithful dataset contains two variables.

##   eruptions waiting
## 1     3.600      79
## 2     1.800      54
## 3     3.333      74
## 4     2.283      62
## 5     4.533      85
## 6     2.883      55

A scatter plot with default font size

Let us make a simple scatter plot in R using ggplot2. We will change the theme of the plot to theme_bw() from the default theme_grey() in ggplot2.

# make simple scatter plot
faithful %>% 
  ggplot(aes(x=eruptions,y=waiting)) +
  geom_point() +
  theme_bw()

By default, in ggplot2, the text size along the axes in ggplot is pretty small. If you save the plot and use it in a document, the axis text will not be legible at all. See the example scatter plot below and notice how small the axis label text is.

Increasing the font size using theme’s base_size

There are more than one way to increase the axis label font. Since we are already using a theme definition for our plot with theme_bw(), we can change the text font size of axes labels and the tick mark labels at one go.

We can increase the axis label size by specifying the argument base_size=24 inside theme_bw().

faithful %>% 
  ggplot(aes(x=eruptions,y=waiting)) +
  geom_point() +
  theme_bw(base_size=24)

ggplot2 uses the specified base_size and increases label text and tick text as shown below

theme_bw(base_size = 11,
         base_family = "",
         base_line_size = base_size/22,
         base_rect_size = base_size/22)

Now, we can see that we have increased the font size of text on both the axes and the tick mark text.

If you are interested in customizing the plot you made with ggplot2 in R, you might want to check out the post on how to change axis labels, how to add multi-line axis labels, and how to set title & subtitle to a plot made with ggplot2.

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: change axis font size, ggplot2, R Tagged With: ggplot2, R

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