scale_fill_continuous in R
The scale_fill_continuous()
method is from ggplot2
package. This tutorial demonstrates how and where to use scale_fill_continuous()
method in R.
Scale Fill Continuous in R
The scale_fill_continuous
method is a default color scale for the ggplot2
package when the continuous
are mapped onto the fill
. The syntax for this method is:
scale_fill_continuous(..., type = getOption("ggplot2.continuous.fill"))
The method uses options()
to determine default settings. Where ggplot2.continuous.fill
is the default value to the continuous
color scale.
The argument to the scale_fill_continuous
method can be Viridis
or gradient
. Let’s try an example of this method.
First, load the ggplot2
package and create a ggplot
graph.
library(ggplot2)
DemoGraph <- ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_tile()
DemoGraph
We can now give patterns to the graph using the scale_fill_continuous()
method. See example:
DemoGraph + scale_fill_continuous(type = "gradient")
The code above gives a gradient pattern to the graph. See output:
We can also use the Viridis
option in the scale_fill_continuous
method.
DemoGraph + scale_fill_continuous(type = "viridis")
The code above gives the Viridis
pattern, highlighting the graph’s points. See output:
Here is the full code for convenience.
library(ggplot2)
DemoGraph <- ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_tile()
DemoGraph
DemoGraph + scale_fill_continuous(type = "gradient")
DemoGraph + scale_fill_continuous(type = "viridis")
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
LinkedIn Facebook