背景
?scale_fill_manual
的帮助说:
<小时/>...: 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())
<小时/>
问题
但是如果我想将调色板功能添加到比例中,它就不起作用:
p + scale_fill_manual(palette = my_pal)
# Error in as.vector(x, "character") :
# cannot coerce type 'closure' to vector of type 'character'
<小时/>
问题
如何正确使用palette
参数?我知道如何正确设置颜色,但我想了解 palette
参数的用途以及如何使用它。如果它是一个内部参数,我想知道为什么它首先在 scale_*_manual
API 中可用。
最佳答案
这似乎是一个错误。请参阅(已关闭)问题:scale_colour_manual(palette=foo): cannot coerce type 'closure' to vector of type 'character' :
@sjackman:
How is the
palette
argument meant to be used; is there an example in the documentation?
@克劳斯威尔克:
It's not meant to be used at all. The bug is that
palette
is accessible and mentioned in the documentation.
关于r - 在scale_*_manual中使用palette参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56556842/