The scale_colour_fermenter() is a ggplot2 package’s function in R that adjusts the color of a categorical variable in a plot based on a specified color palette. It changes the color of a variable mapped to the color aesthetic in a ggplot2 plot.
The scale_colour_fermenter() function takes a few arguments, including the name of the color palette to use (palette), the name of the variable to adjust the color for (name), and whether or not to reverse the order of the colors in the palette (reverse).
Syntax
scale_fill_fermenter(
...,
type = "seq",
palette = 1,
direction = -1,
na.value = "grey50",
guide = "coloursteps",
aesthetics = "fill"
)
Parameters
type: It is one of “seq” (sequential), “div” (diverging), or “qual” (qualitative)
palette: If a string will use that named palette. If a number will index into the list of palettes of the appropriate type. The list of available palettes can be found in the Palettes section.
direction: It sets the order of colors in the scale. If 1, the default colors are as output by RColorBrewer::brewer.pal(). If -1, the order of colors is reversed.
aesthetics: The character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with.
na.value: It is a color for missing values
guide: Type of legend. Use “colourbar” for continuous color bar or “legend” for discrete color legend.
…: Other arguments.
Example
library(ggplot2)
# Create a scatterplot of mpg vs. hp, with points colored by the number of cylinders
p <- ggplot(mtcars, aes(x = hp, y = mpg, colour = cyl)) +
geom_point()
# Adjust the color of the points using the scale_colour_fermenter() function
p + scale_colour_fermenter(palette = 1, name = "Cylinders")
Output
In this example, we created a scatterplot of miles per gallon (mpg) vs. horsepower (hp), with the points colored according to the number of cylinders (cyl).
The scale_colour_fermenter() function is used to adjust the colors of the points based on the “plasma” color palette and to add a legend title of “Cylinders”.
That’s it.
Related posts

Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language.