Table of Contents
The visual presentation of data is paramount in effective communication. When creating visualizations using the powerful ggplot2 package in R, analysts often seek to minimize unnecessary visual clutter to emphasize the data itself—a concept known as maximizing the data-ink ratio. One of the most common elements targeted for removal is the background gridlines, which, while helpful for precise reading, can sometimes distract from the overall trend or pattern. Fortunately, ggplot2 provides incredibly flexible tools for theme manipulation, allowing for the complete suppression or precise customization of these grid elements.
The primary method for controlling plot aesthetics, including gridlines, involves utilizing the theme() function. Specifically, removing all gridlines is achieved by assigning the element_blank() argument to the core plotting element, panel.grid. This action ensures a clean, whitespace background for your visual display. Furthermore, ggplot2 allows for granular control over the major and minor gridlines, as well as their orientation (vertical or horizontal), through specialized arguments like panel.grid.major.x, panel.grid.major.y, panel.grid.minor.x, and panel.grid.minor.y. Understanding these parameters is key to achieving highly specific plot designs.
Quick Method: Using Predefined Themes like theme_classic()
For users seeking the fastest route to a clean plot, ggplot2 offers several built-in themes that automatically strip away many default visual elements, including the standard gray background and gridlines. The easiest and most common of these is the theme_classic() function. This theme is highly effective because it removes the panel background, major and minor gridlines, and draws only the axis lines and ticks, providing a professional and minimalist appearance with minimal coding effort. This approach is ideal when a quick, publication-ready plot is required without needing complex theme adjustments.
Implementing theme_classic() is straightforward. It is simply added as a layer to your existing ggplot2 object, overriding the default aesthetics defined by theme_gray() (which is the default theme applied to all ggplot2 plots). The following code snippet demonstrates how easily theme_classic() can transform a plot by instantly removing all grid elements and the gray panel background, leaving behind a crisp, white canvas.
ggplot(df, aes(x=x, y=y)) +
geom_point() +
theme_classic()
Method 2: Achieving Granular Control Using the theme() Function
While predefined themes like theme_classic() are convenient, they impose specific design choices (e.g., removal of the panel border). For developers who require fine-tuned control—perhaps keeping a specific background color, maintaining the panel border, or only removing minor gridlines—the explicit use of the theme() function is necessary. The theme() function allows you to directly manipulate almost every non-data element in the plot, passing specific arguments to customize their appearance.
To remove all gridlines while retaining maximum control over other elements, we start by applying a base theme that provides certain structure, such as theme_bw() (Black and White), which includes a panel border. We then use theme() to selectively override the grid elements, setting them to element_blank(). This approach ensures that only the intended elements (the gridlines) are removed, leaving other structural elements like the panel background color or borders intact unless explicitly overridden. This level of customization is crucial for advanced data visualization projects requiring strict adherence to corporate or publication style guides.
The following comprehensive syntax demonstrates how to build a fully customized, minimalist plot. Here, we specifically remove major and minor gridlines, the panel border, and the plot background, while ensuring the axes themselves remain visible and are drawn with a black line, providing a truly clean aesthetic similar to theme_classic() but achieved through explicit manual control.
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())
Example 1: Implementing theme_classic() for Clean Plots
This example illustrates the practical application of theme_classic(). We first define a simple dataset structure, which is a standard data frame in R containing simple X and Y coordinates. The goal is to generate a scatter plot where the visual emphasis is placed entirely on the relationship between the variables, without any distracting gridlines or colored backgrounds. This method is highly recommended for preliminary analysis or simple visualizations where deep customization is not required.
Upon defining the data structure, we initialize the ggplot2 object, specify the aesthetic mappings (aes) for the X and Y variables, and add the geometric layer (geom_point()) to render the data points. The final step is simply layering the theme_classic() function. This single line of code handles the removal of both the major and minor gridlines, the gray background panel, and ensures that only the axes and ticks remain.
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()

Granular Control: Targeting Gridline Components (Major and Minor)
Gridlines in ggplot2 are categorized into two types: major and minor. Major gridlines correspond to the primary tick marks on the axes, typically labeled, while minor gridlines appear between the major ticks, offering finer visual reference points. When customizing themes using theme(), we can target these components independently. Using panel.grid.major = element_blank() removes only the primary gridlines, while panel.grid.minor = element_blank() removes only the secondary, intermediate lines. This separation allows for hybrid designs, where one might keep major lines for rough orientation but remove minor lines to reduce density.
If the goal is to remove all gridlines using the theme() function, the most explicit method is to set both panel.grid.major and panel.grid.minor to element_blank(), as demonstrated in the previous complex example. However, an even more concise method exists: by simply specifying panel.grid = element_blank(), ggplot2 correctly interprets this as a command to suppress both major and minor grid components simultaneously, simplifying the code when a full removal is required.
Achieving a minimalist aesthetic often requires overriding the default settings of base themes like theme_bw(). By explicitly setting elements like plot.background and panel.border to element_blank(), we ensure that the plot maintains a clean, borderless, and background-free appearance, relying solely on the data points and the defined axes. This detailed level of theme manipulation is fundamental for producing highly customized, publication-quality graphics where every pixel is intentionally placed.
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())

Targeting Orientation: Removing Specific Vertical or Horizontal Gridlines
Beyond distinguishing between major and minor gridlines, ggplot2 provides functionality to target gridlines based on their orientation: vertical (X-axis) or horizontal (Y-axis). This is particularly useful when one dimension is discrete or nominal (where vertical lines might clutter the display) or when the data only requires precise reference against one axis, such as time series data which often benefits from horizontal lines marking critical values.
The arguments for orientation control are extensions of the core grid components: panel.grid.major.x and panel.grid.major.y control the primary vertical and horizontal lines, respectively. Similarly, panel.grid.minor.x and panel.grid.minor.y manage the secondary lines. By selectively setting one of these arguments to element_blank(), we can create plots that are cleaner than the default but still provide some structural reference along the remaining axis. For instance, if you wish to remove only the vertical gridlines (major and minor) while retaining all horizontal gridlines, you would need to set both panel.grid.major.x = element_blank() and panel.grid.minor.x = element_blank().
Example 2: Maintaining Major Gridlines While Removing Minor Ones
In certain analytical contexts, major gridlines are necessary reference points, but minor gridlines introduce excessive noise. This example demonstrates how to selectively suppress the minor grid elements while preserving the major gridlines using the detailed customization capabilities of the theme() function. We begin with theme_bw() to establish a clear panel structure and then explicitly target only the minor grid components for removal.
By setting panel.grid.minor = element_blank(), we ensure that the intermediate gridlines vanish, yet the primary gridlines remain visible. This technique strikes a balance between visual simplicity and precise data interpretation, offering just enough guidance without overwhelming the viewer. Note that in this specific example, we still remove the plot.background and panel.border to achieve a minimalist foundation, focusing the viewer’s attention purely on the data points relative to the major grid divisions.
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())

Example 3: Removing All Gridlines While Keeping the Panel Border
A common design preference, particularly in statistical reports, is to remove all internal gridlines but maintain a bounding box around the plot area defined by the axes. This frame helps delineate the plotting region clearly from the surrounding document text. Achieving this requires using a base theme that supports a panel border, like theme_bw(), and then explicitly removing the gridlines while ensuring the border remains active.
In this example, we simultaneously set both panel.grid.major and panel.grid.minor to element_blank() to ensure a fully clean panel interior. Crucially, unlike the previous examples where we set panel.border = element_blank(), here we omit that command entirely. Since theme_bw() defaults to drawing a black panel border, removing the gridlines but leaving the border setting untouched results in the desired effect: a clean white plot bounded by a solid frame. This illustrates the precision afforded by layering the theme() function over a predefined base theme to achieve nuanced aesthetic outcomes.
This technique is highly valuable for generating figures that need clear visual separation from adjacent figures or text. By utilizing theme_bw() as the foundation and overriding only the grid elements, we demonstrate how powerful and flexible ggplot2 is for customizing complex visualizations to fit diverse styling requirements, ensuring the final output is both clean and structurally sound.
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())

Summary of Gridline Removal Techniques
Mastering the removal and customization of gridlines is an essential skill for any user aiming to produce professional graphics with ggplot2. Whether opting for the simplicity of predefined themes or the detailed control offered by explicit theme settings, the toolkit provided by the package allows for complete aesthetic freedom. Always consider the ultimate purpose of the visualization: if precise value estimation is needed, faint major gridlines might be useful; if the focus is on overall trends, a completely blank panel is preferable.
Quick Removal: Use theme_classic() or theme_void() to immediately strip away most non-data elements, including all gridlines, panel borders, and backgrounds. This offers the fastest route to a minimalist plot.
Full Control: Apply theme(panel.grid = element_blank()) over a base theme (like theme_bw()) to remove both major and minor gridlines while maintaining control over the panel border and background colors.
Selective Removal: Use specific arguments such as panel.grid.major.y = element_blank() to target specific orientations or types of gridlines, allowing hybrid plots that are partially grid-free.
By employing these methods, you can ensure your ggplot2 plots are visually optimized, directing the audience’s attention entirely to the substantive message conveyed by the data.
Cite this article
stats writer (2025). How to Easily Remove Gridlines from ggplot2 Plots. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-remove-gridlines-in-ggplot2-with-examples/
stats writer. "How to Easily Remove Gridlines from ggplot2 Plots." PSYCHOLOGICAL SCALES, 5 Dec. 2025, https://scales.arabpsychology.com/stats/how-to-remove-gridlines-in-ggplot2-with-examples/.
stats writer. "How to Easily Remove Gridlines from ggplot2 Plots." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-remove-gridlines-in-ggplot2-with-examples/.
stats writer (2025) 'How to Easily Remove Gridlines from ggplot2 Plots', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-remove-gridlines-in-ggplot2-with-examples/.
[1] stats writer, "How to Easily Remove Gridlines from ggplot2 Plots," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, December, 2025.
stats writer. How to Easily Remove Gridlines from ggplot2 Plots. PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.
