# R 中的 scale_fill_continuous

Sheeraz Gul 2022年7月18日 R R Plot

`scale_fill_continuous()` 方法來自 `ggplot2` 包。本教程演示如何以及在何處使用 R 中的 `scale_fill_continuous()` 方法。

## R 中的比例填充連續

`continuous` 對映到 `fill` 時，`scale_fill_continuous` 方法是 `ggplot2` 包的預設顏色比例。此方法的語法是：

``````scale_fill_continuous(..., type = getOption("ggplot2.continuous.fill"))
``````

`scale_fill_continuous` 方法的引數可以是 `Viridis``gradient`。讓我們試試這個方法的一個例子。

``````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")
``````

``````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")
``````
Author: Sheeraz Gul

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.