0

Any idea on how to avoid the below reproducible error please?

df <- data.frame(x,x,x,x,x,x,x,x,y,y,y,y,y,y,y)
data <- df %>% pivot_longer(all_of(setdiff(colnames(df),'x')))
plot_calc <- ggplot(data, aes(x=x))+
  geom_bar(aes(fill=name, y=value, x=x),position="stack", stat="identity")+
  theme(legend.position="bottom",
        legend.key.size = grid::unit(0.1, "inch"),
        legend.key.width = grid::unit(0.1, "inch"))+
    scale_colour_manual("", 
      values = RColorBrewer::brewer.pal(name='Paired', n=12))


legg <- cowplot::get_legend(p1)
Warning message:
In RColorBrewer::brewer.pal(n, pal) :
  n too large, allowed maximum for palette Spectral is 11
Returning the palette you asked for with that many colors

enter image description here

gaut
  • 5,771
  • 1
  • 14
  • 45
  • 2
    I think this is an error from RColorBrewer telling you that it cannot generate a palette with 12 colors, because there aren't that many colors available in the "paired" palette. This doesn't have anything to do with cowplot. – Allan Cameron Aug 08 '22 at 16:13
  • 1
    A quick search "ggplot increase number of colors palette" results in relevant posts, I think. – Henrik Aug 08 '22 at 17:37

0 Answers0