scale _ * _ manual中调色板参数的用法

tho*_*hal 5 r ggplot2

背景

的帮助?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.
Run Code Online (Sandbox Code Playgroud)

因此,我尝试:

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_*_manualAPI中可用。

Hen*_*rik 4

这似乎是一个错误。请参阅(已关闭)问题:scale_colour_manual(palette=foo):无法强制类型“closure”为“character”类型的向量

@斯杰克曼:

如何palette使用该论证?文档中有示例吗?

@克劳斯威尔克:

它根本不是用来使用的。该错误是palette可以访问并在文档中提到的。