2017-12-18 18 views
1

我创建一个条形图这样的条形图:皮条客与预定义的颜色

cyl.am <- ggplot(mtcars, aes(x = factor(cyl), fill = factor(am))) 
cyl.am + 
geom_bar() 

,我想用我自己的颜色香料它一点。然而,当我这样做:

cbbPalette <- c("#000000", "#E69F00") 
cyl.am + 
geom_bar() + 
scale_fill_brewer(palette = cbbPalette) 

我收到以下警告消息,对这里出了什么问题的任何想法?

Warning messages: 
1: In if (!palette %in% unlist(brewer)) { : 
the condition has length > 1 and only the first element will be used 
2: In pal_name(palette, type) : Unknown palette #000000#E69F00 

回答

3

尝试用scale_fill_manual代替:

cbbPalette <- c("#000000", "#E69F00") 
cyl.am <- ggplot(mtcars, aes(x = factor(cyl), fill = factor(am))) 

cyl.am + 
    geom_bar() + 
    scale_fill_manual(values = cbbPalette) 

enter image description here