Colors of Base R Plots Have Changed - Can I Revert to Old Palette?
In recent versions of R, including R 4.0.0, the default color palette for base plots has undergone a significant change. This change affects various aspects of data visualization, making it essential to understand the new color scheme and how to revert to the old one.
Background and Context
The palette()
function in R is responsible for specifying the set of colors used in graphics devices such as the default Windows plot device or postscript. The palette
function returns a named vector containing the specified colors, which are then mapped to the different elements of an object (e.g., data points).
In R 4.0.0, the default color palette was updated to have better accessibility properties and less saturated colors. However, some users may prefer the original color scheme for various reasons.
Why has the color palette changed?
The change in color palette is part of a broader effort to improve the accessibility of R’s graphics. The new colors are designed to be more visible and readable for people with visual impairments. Additionally, the updated palette aims to reduce color clashes between different elements on a plot.
Reverting to the Old Color Palette
Fortunately, users can easily revert to the old color palette by using the palette("R3")
function. This option maps the original default colors used in earlier versions of R.
Understanding the New Default Colors
The new default colors are:
- “black”
- “#DF536B” (a reddish-brown color)
- “#61D04F” (a greenish-yellow color)
- “#2297E6” (a blueish-purple color)
- “#28E2E5” (a cyanish-green color)
- “#CD0BBC” (a magentaish-pink color)
- “#F5C710” (an orangeish-yellow color)
- “gray62”
Example Usage
Here’s an example demonstrating how to revert to the old color palette:
# Revert to the old default palette
palette("R3")
# Display the updated colors
palette()
# [1] "black" "red" "green3" "blue" "cyan" "magenta" "yellow" "gray"
Alternative Ways to Change Colors
Besides using palette("R3")
, you can also change colors by specifying a custom palette or using the par()
function with specific color mappings.
For example, to use a different color mapping:
# Create a new color mapping
colorMapping <- c(
"black" = "#000000",
"red" = "#FF0000",
"green3" = "#00FF00"
)
# Update the color palette with the custom mapping
palette(colorMapping)
Why Not Use par()
Function?
While you can use the par()
function to customize your plot colors, it’s essential to understand that using this method can lead to inconsistent results across different R versions and environments.
In contrast, using the palette("R3")
function ensures that you’re working with a specific color palette designed for earlier versions of R, making it easier to maintain consistency in your visualizations.
Best Practices
When working with base plots in R 4.0.0 and later, keep the following best practices in mind:
- Use
palette("R3")
if you need to revert to the original color palette. - Consider using a custom color mapping for specific visualizations to ensure consistency.
- Always check your plot colors across different environments and R versions.
Conclusion
The change in the default color palette in R 4.0.0 is part of a broader effort to improve accessibility and reduce color clashes in data visualization. By understanding how to revert to the old color palette using palette("R3")
, you can maintain consistency in your visualizations while still taking advantage of the updated colors designed for better accessibility.
Remember to consider customizing your color mappings or using alternative methods if you need more control over your plot colors.
Last modified on 2025-02-21