背景
的帮助?scale_fill_manual
说:
Run Code Online (Sandbox Code Playgroud)...: Arguments passed on to ‘discrete_scale’ palette A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that they should take.
码
因此,我尝试:
library(ggplot)
library(dplyr)
my_pal <- colorRampPalette(1:3)
(p <- ggplot(mtcars %>%
group_by(cyl) %>%
summarise(mpg = mean(mpg)),
aes(x = factor(cyl), y = mpg, fill = factor(cyl))) +
geom_col())
Run Code Online (Sandbox Code Playgroud)
问题
但是,如果我想将调色板功能添加到比例尺,它将无法正常工作:
p + scale_fill_manual(palette = my_pal)
# Error in as.vector(x, "character") :
# cannot coerce type 'closure' to vector of type 'character'
Run Code Online (Sandbox Code Playgroud)
题
如何palette
正确使用参数?我知道如何正确设置颜色,但是我想了解palette
参数的含义以及如何使用它。如果它是一个内部参数,我想知道为什么它首先在scale_*_manual
API中可用。
这似乎是一个错误。请参阅(已关闭)问题:scale_colour_manual(palette=foo):无法强制类型“closure”为“character”类型的向量:
@斯杰克曼:
如何
palette
使用该论证?文档中有示例吗?
@克劳斯威尔克:
它根本不是用来使用的。该错误是
palette
可以访问并在文档中提到的。
归档时间: |
|
查看次数: |
54 次 |
最近记录: |