Table of Contents
The process of removing gridlines in ggplot2 involves adjusting the theme settings of the plot. This can be done by specifying the theme option “panel.grid” and setting it to “blank”. This will remove all gridlines from the plot. Alternatively, specific gridlines can be removed by specifying the theme option “panel.grid.major” or “panel.grid.minor” and setting it to “blank”. This allows for a more customized removal of gridlines in ggplot2.
Remove Gridlines in ggplot2 (With Examples)
The easiest way to remove gridlines in ggplot2 is to use theme_classic():
ggplot(df, aes(x=x, y=y)) +
geom_point() +
theme_classic()
Alternatively, you can use the following syntax to remove specific gridlines:
ggplot(df, aes(x=x, y=y)) + geom_point() + theme_bw() + theme(axis.line = element_line(color='black'), plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank())
The following examples show how to use both of these methods in practice.
Example 1: Remove Gridlines with theme_classic()
The following code shows how to remove gridlines from a ggplot2 plot using theme_classic():
library(ggplot2) #define data df <- data.frame(x=c(1, 2, 3, 4, 5, 6), y=c(6, 8, 14, 19, 29, 31)) #create ggplot with no gridlines ggplot(df, aes(x=x, y=y)) + geom_point() + theme_classic()

Example 2: Remove Specific Gridlines
The following code shows how to remove gridlines from a ggplot2 plot using a bit more customization:
library(ggplot2) #define data df <- data.frame(x=c(1, 2, 3, 4, 5, 6), y=c(6, 8, 14, 19, 29, 31)) #create ggplot with no gridlines ggplot(df, aes(x=x, y=y)) + geom_point() + theme_bw() + theme(axis.line = element_line(color='black'), plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank())

This code allows you to remove specific gridlines. For example, we could use the following code to keep the major gridlines in the plot:
library(ggplot2) #define data df <- data.frame(x=c(1, 2, 3, 4, 5, 6), y=c(6, 8, 14, 19, 29, 31)) #create ggplot with no gridlines ggplot(df, aes(x=x, y=y)) + geom_point() + theme_bw() + theme(axis.line = element_line(color='black'), plot.background = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank())

Alternatively, we could use the following code to remove all gridlines but keep the panel border in the plot:
library(ggplot2) #define data df <- data.frame(x=c(1, 2, 3, 4, 5, 6), y=c(6, 8, 14, 19, 29, 31)) #create ggplot with no gridlines ggplot(df, aes(x=x, y=y)) + geom_point() + theme_bw() + theme(axis.line = element_line(color='black'), plot.background = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank())

Cite this article
stats writer (2024). How can I remove gridlines in ggplot2?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-remove-gridlines-in-ggplot2/
stats writer. "How can I remove gridlines in ggplot2?." PSYCHOLOGICAL SCALES, 1 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-remove-gridlines-in-ggplot2/.
stats writer. "How can I remove gridlines in ggplot2?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-remove-gridlines-in-ggplot2/.
stats writer (2024) 'How can I remove gridlines in ggplot2?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-remove-gridlines-in-ggplot2/.
[1] stats writer, "How can I remove gridlines in ggplot2?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can I remove gridlines in ggplot2?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
