11

Having installed tidyverse, I can't get the following to work....

ggplot(iris, aes(x = Sepal.Length, fill = Species) + geom_density(alpha = .3)

The error reads: "Error: Must request at least one colour from a hue palette."

Any ideas?

stixmcvix
  • 313
  • 1
  • 2
  • 10
  • i suppose, you have not have not provide the whole your code? am i right? – Sal-laS Sep 05 '18 at 10:51
  • 1
    it has nothing to do with your update of packages. if you are suspect of it, restart your RStudio. But, i think, the problem comes from your code which you did not share it with us. – Sal-laS Sep 05 '18 at 10:57
  • 2
    Hi @Salman restarting it seems to have cleared the problem, so thank you for the tip :) FYI - the only code that preceded the line in my original question was: `library(tidyverse)` – stixmcvix Sep 06 '18 at 11:07

5 Answers5

11

Just for the record and for future readers, I had this error related with the specific column (iris$Species in this example) containing only NAs.

This happened because some libraries did not work properly after sourcing my code, and therefore some tables didn't have the proper format.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Carles Borredá
  • 358
  • 2
  • 8
6

I cannot get this error from your code. Your code works well, you just missed a close parentheses ):

ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
         geom_density(alpha = .3)

The result is:

enter image description here

Sal-laS
  • 11,016
  • 25
  • 99
  • 169
  • Yeah my bad, missed the extra ) but even then it still fails for me. Can't help thinking this is linked to me updating my packages yesterday in R Studio, and since then I've had no end of problems (not finding "stringi" package for example). – stixmcvix Sep 05 '18 at 10:50
1

just for the record and for future readers, sometimes the sourcing of the code does not work

source("code_that_generates_data_for_ggplot.R")

and the data that is the GGPLOT input have one or more missing variables. This happens since some of the data is encoded in UTF-8.

A possible solution to this is using

source("code_that_generates_data_for_ggplot.R", encoding="UTF-8")

instead

amann
  • 369
  • 1
  • 8
1

I had the same problem because I was calling a column witch a forgot to fill.

andhherson
  • 37
  • 4
0

This error comes if the column given as 'fill' contain all NAs.

So effectively it does not request for any color.

That would explain the error

"Error: Must request at least one colour from a hue palette."

I tried the below code, with 'condition' containing only NAs, and obtained the same error

  ggplot(grouped_info) +
    geom_bar(aes(x = label, y = n, fill = condition), stat = "identity")
abhivij
  • 117
  • 8