我有一个有序因子变量,我想使用 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/