In this post, we learn how to make axis tick labels bold in ggplot2 R. If you wonder what are axis tick labels, they are the text labels that appear right below the tick marks on a graph’s x and y axes. These labels play an omportant role in helping interpret the values represented on the axes. This, making the tick labels bold can enhance the plot made with ggplot2.
library(tidyverse) library(palmerpenguins) theme_set(theme_bw(16))
How to make axis tick labels bold?
Let us use a scatter plot made with ggplot2 to show how to make the axis tick labels bold.
penguins |> ggplot(aes(body_mass_g, bill_length_mm, color=species))+ geom_point()+ labs(title="How to make axis tick labels bold in ggplot2") ggsave("how_to_make_axis_tick_labels_bold_ggplot2.png")
Notice that the tick labels are not bold by default in ggplot.
Make x-axis tick labels bold using axis.text.x
ggplot2 offers great controls over how to customize axis tick labels. If you are interested in just making the x-axis tick labels, we can use axis.text.x as argument to theme() function as shown below. In the examples we use in this post, we have also changed the tick label size using size argument to element_text().
penguins |> ggplot(aes(body_mass_g, bill_length_mm, color=species)) + geom_point() + theme(axis.text.x= element_text(size=15, face="bold"))+ labs(title=stringr::str_wrap("Make x-axis tick label bold in ggplot2 with element_text()", width=40)) ggsave("make_x_axis_tick_labels_bold_ggplot2_using_theme.png")
Make y-axis tick labels bold using axis.text.y
Similarly, we can make the y-axis tick labels bold, by using axis.text.y as argument to theme() function as shown below.
penguins |> ggplot(aes(body_mass_g, bill_length_mm, color=species))+ geom_point() + theme(axis.text.y= element_text(size=15, face="bold"))+ labs(title=stringr::str_wrap("Make y-axis tick label bold in ggplot2 with element_text()", width=40)) ggsave("make_y_axis_tick_labels_bold_ggplot2_using_theme.png")
Make both the axes tick labels bold using axis.text
To make both the axes’ tick labels bold, by using axis.text as argument to theme() function with element_text() function. In the examples we also set the size of the axis tick labels as shown below.
penguins |> ggplot(aes(body_mass_g, bill_length_mm, color=species))+ geom_point() + theme(axis.text= element_text(size=15, face="bold"))+ labs(title=stringr::str_wrap("Make axis tick label bold in ggplot2 with element_text()", width=40)) ggsave("make_axis_tick_labels_bold_ggplot2_using_theme.png")