Customizing in the ggplot2 theme - Advanced theme settings
In data visualization, visual appeal is just as important as conveying information. The ggplot2 theme option allows you to customize the background, fonts, and colors of your graphs.
In this post, we'll walk you step-by-step through advanced theme settings that go beyond the default settings to make your data stand out even more. First, we'll start with the ggplot2 packageso that even if you're new to it, you can follow along.
Need to set up ggplot2 theme
While ggplot2's default theme is clean and efficient, you'll often want to give it a more unique style. Whether you're creating graphs for a presentation or a report, customizing your theme will make your data stand out.
1. Explore the default theme settings
ggplot2 provides several default theme options to make it easy to change the style. Let's take a look at some of the most common default themes: #Minimal/Classic/Dark Theme When you run the action part of the code description, you should see the graphs in the order shown at the bottom of the code description.
Load the # library
library(ggplot2)
library(showtext)
Display the # graph in Korean
showtext_auto()
Create # example data
data <- data.frame(
x = rnorm(100),
y = rnorm(100)
)
# default theme example
p <- ggplot(data, aes(x = x, y = y)) +
geom_point()
labs(title = "minimal theme")
p + theme_minimal() Apply # minimal theme
p + theme_classic() apply # classic theme
p + theme_dark() # Applies the dark themeCode description:
- theme_minimal(): Apply a minimalist theme with a simple background and preserved grid lines.
- theme_classic(): Use the classic theme with a traditional white background and only the axis visible.
- theme_dark(): A dark theme with a black background, making data points stand out strongly.



2. set a custom theme with the theme() function
Now let's use the theme() function to fully customize the ggplot2 theme. You can set the graph background, grid lines, axis titles, and much more.
Applying a # custom theme
p + theme(
panel.background = element_rect(fill = "lightgray"),
plot.title = element_text(size = 16, face = "bold"),
axis.title = element_text(size = 14, face = "italic"),
axis.text = element_text(color = "blue"),
panel.grid.major = element_line(color = "white", size = 0.5),
panel.grid.minor = element_blank()
)Code description:
- panel.background = element_rect(fill = "lightgray"): Sets the panel background to light gray.
- plot.title = element_text(size = 16, face = "bold"): Set the graph title to bold and size to 16.
- axis.title = element_text(size = 14, face = "italic"): Set the axis title to italic and resize it to 14.
- axis.text = element_text(color = "blue"): Sets the axis label color to blue.
- panel.grid.major = element_line(color = "white", size = 0.5): Sets the major grid line to a thin white color.
- panel.grid.minor = element_blank(): Remove the minor grid lines.

3. create a backgroundless graph with theme_void()
Finally, we'll use theme_void() to create a clean graph with both background and axes removed, which is great for logo design or presentations.
# Backgroundless Graph
p + theme_void() +
labs(title = "Backgroundless theme example")Code description:
- theme_void(): Removes all backgrounds, axes, grids, etc. so that only the graph data stands out.

Wrapping Up: Complete your look with the ggplot2 theme!
You can now fully customize the style of your graphs with the ggplot2 theme option. Use the theme() function to adjust the background, fonts, and colors to maximize the visual appeal of your graphs. In the next post Introduction to ggplot2's interactivity featuresStay tuned for more colorful visualizations!





