r - 离散化 viridis ggplot 色标

标签 r ggplot2 colors viridis

我有一个有序因子变量,我想使用 ggplot2 来绘制它。有什么方法可以使用 scale_color_viridis() (连续色阶)与此有序因子,而不将因子转换为数字?简单明了

iris$Sepal.Width <- ordered(iris$Sepal.Width)

ggplot(iris, aes(Sepal.Length, Petal.Length, color=Sepal.Width)) + 
  geom_point() + 
  scale_color_continuous()

不起作用。

最佳答案

Viridis 有一个discrete = TRUE 选项。

iris$Sepal.Width <- ordered(iris$Sepal.Width)

ggplot(iris, aes(Sepal.Length, Petal.Length, color=Sepal.Width)) + 
geom_point() + 
viridis::scale_color_viridis(discrete = TRUE)

关于r - 离散化 viridis ggplot 色标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42728144/

相关文章:

r - 如何创建一个新列,其中包含 df 中的唯一值计数(按 r 中的组)

r - R 中 facet_grid() 的 labeller() 函数内的 tidy_eval

r - 堆积条形图 : what if each subcategory (fill) is unique?

c++ - 如何使用 R CMD 安装 R 库

r - 无法从 github 安装包 - 无法解释的错误消息

ggplot2 - 使用 ggarrange 添加行和列标题

java - Android在某个时间段给TextView着色

c++ - 使用VBO绘制不同宽度的彩色线条?

excel - 可以使用coldfusion读取Excel工作表上单元格的背景颜色

r - 尝试从 glmnet 模型中提取系数返回 NULL 或 "type must be either "raw"或 "prob""错误