What is scale_fill_fermenter() Function in R

The scale_fill_fermenter() is a function in the ggplot2 package of R used to apply a color scale to the fill aesthetic of a plot. It creates a sequential color palette that ranges from a light color to a dark color, with the colors chosen to be perceptually uniform.


  type = "seq",
  palette = 1,
  direction = -1,
  na.value = "grey50",
  guide = "coloursteps",
  aesthetics = "fill"


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.



# Create a sample data frame
df <- data.frame(x = 1:10, y = 1:10, z = 1:10)

# Create a ggplot object and map the fill aesthetic to the z variable
ggplot(df, aes(x, y, fill = z)) +
 # Add a tile layer to create a heatmap
 geom_tile() +
 # Apply a color scale to the fill aesthetic using scale_fill_fermenter()


What is scale_fill_fermenter() Function in R

You can see that it created a heatmap with a color scale that ranges from dark blue to light blue. You can customize the color scale by changing the arguments of scale_fill_fermenter().

The scale_fill_fermenter() function takes several arguments that allow you to customize the color palette to your liking, including the number of colors to use (n), the direction of the color gradient (direction), and the type of color interpolation to use (type).

By default, scale_fill_fermenter() uses the “magma” color palette, a popular color palette ranging from black to yellow to red.

You can use this function to map a continuous variable onto the fill aesthetic of a plot and create discrete bins of colors.

That’s it.

Leave a Comment