我有这个包含20个cty组的数据框的代码。我希望为每个特定的cty值绘制/分配一个基于Wes安德森调色板的颜色(包(“Wesanderson”)。
代码:
library(ggplot2)
library(wesanderson)
df <- mpg[, c("displ","cyl", "cty", "hwy" )]
df[-222,]
pal <- wes_palette(20, name = "Zissou1", type = "continuous")
ggplot(df, aes(x=hwy, y=displ, group=cyl)) +
geom_point(aes(color=cty)) + scale_color_manual(values= pal)
字符串
但我得到一个错误:
Error in `train_discrete()`:
! Continuous value supplied to a discrete scale
Run `rlang::last_trace()` to see where the error occurred.
型
你知道怎么解决吗
此外,由于一些调色板有4种颜色(例如,GrandBudapest 1、GrandBudapest 2、Moonrise 1、Moonrise 2和Chevalier 1),是否有方法将这5种颜色组合成20种颜色的新调色板?
谢谢.
1条答案
按热度按时间3duebb1j1#
绘图前将cty转换为factor
字符串
的数据
或使用渐变渐变
型
的