R color chart and ggplot2 palettes
Which R color name or HEX value should I use?
R 4.5.3 provides 657 color names covering 502 distinct RGB colors. Browse the swatches, copy a HEX value and use it in your R or ggplot2 figure.
HEX writes a color as # followed by six characters from 0–9 and A–F: two each for red, green and blue. RGB writes those same three components as numbers from 0 to 255. For steelblue, #4682B4 corresponds to RGB 70, 130, 180. You can search either the name or HEX above the full list. Some R names share one color; snow and snow1 both use #FFFAFA.
Which colors can I try first?
Each card shows an R color name and its HEX value. Click a card to copy HEX.
Where are all 657 R color names and HEX values?
Showing 657 of 657 matching colors
How do I apply these colors in ggplot2?
Here I give each group its own entry in cols: A uses #2066B0, B #E18B32, C #5B9279 and D #874EA1. scale_fill_manual(values = cols) matches these names to the group column, so the association follows the group name when the rows change order.
This article uses simulated example data.

The four short blocks below make up the complete program shown afterward. Paste them into one R script in this order. Steps 1–3 prepare the tools, table and plot; step 4 writes the PNG. The R and ggplot2 versions used for the recorded run are 4.5.3 and 4.0.4.
Step 1: Where do I enter the code?
In RStudio, create an R script, a text file that keeps your commands. Save it as the example filename shown below. The Console is the pane where commands run and replies appear. A function is a named operation; parentheses hold its inputs. Quotes enclose text. A # outside quotes starts a reader comment. If ggplot2 is missing, enter install.packages("ggplot2") in the Console once. Then run the first line in the script to load this collection of plotting tools. In the Console, use setwd("full/folder/path") with your own existing folder path in quotes; forward slashes work on Windows too. Then use getwd() to check it. Inside a function call, = supplies a named setting.
library(ggplot2) # Enable the installed ggplot2 package, a collection of plotting tools.Step 2: How do I connect the groups, values and colors?
Each row is one group; the two columns hold its name and value. c() puts values of the same type in order, forming a vector. The first vector holds four names and the second four numbers. data.frame() puts these equally long vectors into columns. The arrow <- stores the result under the name on its left, here dat. cols is another vector, holding four HEX strings with names A–D. For example, A = "#2066B0" attaches the name A to that blue. Keep the spelling and uppercase letters the same as in group; commas separate entries. At this stage dat contains four rows and cols contains four named colors.
dat <- data.frame( # Begin a table with one row per group. group = c("A", "B", "C", "D"), # Put the four text group names in order. value = c(8, 11, 9, 14) # Put the four numeric values in the matching order.) # Finish the table and save it as dat.cols <- c( # Begin a group-to-color vector. A = "#2066B0", B = "#E18B32", # Assign blue to A and orange to B. C = "#5B9279", D = "#874EA1" # Assign green to C and purple to D.) # Save the named color vector as cols.Step 3: Which part sets bar color and which sets height?
ggplot() starts the plot from dat. In aes(), x = group sets the horizontal positions, y = value sets height, and fill = group asks for one interior color per group. geom_col() draws the supplied values from zero. Its width of 0.65 uses category-position units; adjacent category centers are one unit apart. colour = "#313743", outside aes(), gives every bar the same dark outline. scale_fill_manual() supplies the named fill colors. For a variable mapped to line or point colour, use scale_colour_manual(). The + signs add plot components. labs() names the axes; theme_minimal() sets text to 13 points and requests local Arial. Here I hide the legend because A–D already identify the groups below the bars. p holds this prepared plot in memory. Step 4 saves the PNG.
p <- ggplot(dat, aes(x = group, y = value, fill = group)) + # Connect table columns to the plot; + adds the next plot component. geom_col(width = 0.65, colour = "#313743") + # Draw bar heights from value and give the bars a dark outline. scale_fill_manual(values = cols) + # Use group names to match bar fills with the chosen colors. labs(x = "Group", y = "Value") + # Name the horizontal and vertical axes. theme_minimal(base_size = 13, base_family = "Arial") + # Set a simple grid, a base text size of 13 points and Arial. theme(legend.position = "none") # Use the horizontal group labels to identify the colors.Step 4: How do I save and check the PNG?
Enter getwd() in the Console to display the current working folder, the location used by these relative filenames. Choose a writable folder before running the program. Select the whole script and use Run, or use Source to run the file from top to bottom. ggsave() writes palette-example.png there: width 160 and height 100 are millimeters; dpi = 180 is pixels per inch. This Cairo PNG run produced 1133 × 708 pixels with a white background. Open it and check the group letters, heights and four fills against the result above. Arial must be available locally to reproduce the recorded lettering.
ggsave("palette-example.png", plot = p, width = 160, height = 100, # Save plot p at 160 by 100 millimeters in the current folder. units = "mm", dpi = 180, device = grDevices::png, type = "cairo", bg = "white") # Write a PNG at 180 DPI with the Cairo device and a white background.Can I run the complete R example?
library(ggplot2) # Enable the installed ggplot2 package, a collection of plotting tools.dat <- data.frame( # Begin a table with one row per group. group = c("A", "B", "C", "D"), # Put the four text group names in order. value = c(8, 11, 9, 14) # Put the four numeric values in the matching order.) # Finish the table and save it as dat.cols <- c( # Begin a group-to-color vector. A = "#2066B0", B = "#E18B32", # Assign blue to A and orange to B. C = "#5B9279", D = "#874EA1" # Assign green to C and purple to D.) # Save the named color vector as cols.p <- ggplot(dat, aes(x = group, y = value, fill = group)) + # Connect table columns to the plot; + adds the next plot component. geom_col(width = 0.65, colour = "#313743") + # Draw bar heights from value and give the bars a dark outline. scale_fill_manual(values = cols) + # Use group names to match bar fills with the chosen colors. labs(x = "Group", y = "Value") + # Name the horizontal and vertical axes. theme_minimal(base_size = 13, base_family = "Arial") + # Set a simple grid, a base text size of 13 points and Arial. theme(legend.position = "none") # Use the horizontal group labels to identify the colors.ggsave("palette-example.png", plot = p, width = 160, height = 100, # Save plot p at 160 by 100 millimeters in the current folder. units = "mm", dpi = 180, device = grDevices::png, type = "cairo", bg = "white") # Write a PNG at 180 DPI with the Cairo device and a white background.What changes if I make the bars narrower?
Change only width = 0.65 to width = 0.40 in geom_col(). Run the exercise file in a separate writable folder so its palette-example.png keeps the original result available. Predict whether the heights or group colors will change.
See the exercise result
Each bar is now 0.40 category-position units wide, with 0.60 units between neighboring bar edges. Heights remain 8, 11, 9 and 14, with the same four group colors. Compare the narrower bars with the original width of 0.65, whose gap is 0.35.

Which files can I download?
The displayed code matches the R download for this page’s language. The CSV holds all 657 R color names and their RGB/HEX values.
The additional exercise file changes only bar width to 0.40 and writes palette-example.png in the folder where you run it. palette-width040.png is the exercise preview supplied here.
- r-colors.csvAll R color names and values, for sorting or lookup.
- sample-data.csvThe four demonstration groups and their values.
- palette-example.pngThe actual PNG generated by the example code.
- example.en.RThe complete R example with comments in this language.
- run.jsonVersions and checked group-to-color mappings.
- LICENSE.txtUsage license and source information.
- exercise-width040.en.RComplete exercise program with bar width set to 0.40.
- palette-width040.pngPNG result from the bar-width exercise.
How do R and CSS color names differ?
A color name can have different values in R and CSS. Use the HEX value when carrying one of these colors between tools.
| Environment | green | gray |
|---|---|---|
| R 4.5.3 | #00FF00 | #BEBEBE |
| CSS | #008000 | #808080 |
Where do these names and values come from?
The table was generated from R’s colors() and col2rgb() functions, then converted to six-digit HEX. Alias names are retained, so 657 names describe 502 distinct RGB values. Swatches use these HEX values directly.
Learn R