Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing "Must request at least one colour from a hue palette" error in my R package only on linux-based builds?

I am currently checking some code for cross-platform compatibility. I am using Travis-CI to build my R package under ubuntu on GitHub commits. If I eliminate this one single part, it successfully builds, but if I include this code, I receive the error:

Must request at least one colour from a hue palette.

This builds fine and works properly on windows and OS X, this issue is only appearing on the ubutu build. I also want to point out this is happening during the vignette build step that executes the code that follows. This error message appears to originate from this function in the R scales library.

I have some data that looks like this:

gene <- c("ISG20","ISG20","HEY1","ISG20","ACTB","MDM2","CDYL","HEY1","ACTB","UTP3","MDM2") 
variable <- c("6h_ebov","1d_ebov","1d_ebov","2d_ebov","2d_ebov","2d_ebov","2d_restv","2d_restv","2d_restv","2d_restv","2d_restv")
value <- c(-4.54267311671893,0.523667984831315,0.552671011358972,3.97643775389922,0.888734866999937,1.26719604773752,1.31653814202267,2.28445821019938,1.00301304727651,1.86941283629719,1.33916249182697 )

filteredList <- data.frame(gene,variable,value)

> head(filteredData)
   gene variable      value
1 ISG20  6h_ebov -4.5426731
2 ISG20  1d_ebov  0.5236680
3  HEY1  1d_ebov  0.5526710
4 ISG20  2d_ebov  3.9764378
5  ACTB  2d_ebov  0.8887349
6  MDM2  2d_ebov  1.2671960

I am using ggplot2 to display this data, my command is approximately as follows:

library(ggplot2)
library(ggthemes)

stata_long_pal = c(stata_pal("s2color")(15), stata_pal("s1rcolor")(15))
plot_out <- ggplot(filteredList, aes(x=value, y=factor(variable, levels=as.character(unique(variable)), ordered=TRUE), label=variable, col=variable)) + 
        geom_point(stat='identity', aes(col=variable), size=3) +
        theme_stata() + 
        scale_fill_manual(values=stata_long_pal) + 
        theme(axis.text.y = element_text(angle = 45, hjust = 1), plot.title = element_text(size=14, face="bold", hjust=0)) + 
        guides(col=guide_legend(ncol=6%/%3)) +
        theme(legend.text = element_text(size=12)) +
        theme(legend.title=element_blank()) +
        theme(axis.text=element_text(size=12, face="bold")) +
        theme(text = element_text(size=22,margin = margin(t = 0, r = 10, b = 0, l = 0))) +
        labs(x="", y="", title="Differentially Expressed Genes", subtitle="Log2 Fold-Change")

This is the part that is triggering the error. I feel like the issue has to be some little technicality with either the aes() or with scale_fill_manual() maybe. I am attempting to see if changing these around in a few different ways has any effect, but because I'm using Travis-CI it takes quite a while to test after each change.

Does anyone see what might be causing the issue or have any insights into why this is happening? Thanks very much in advance.

EDIT: I would like to point out that I have narrowed the problem down to this bit of code.

geom_point(stat='identity', aes(col=variable), size=3) 

If I do the following it works but my coloring is lost.

geom_point()

EDIT2: I have modified the data section to be more useable. Copy/paste should word directly now.

like image 661
Adam Price Avatar asked Oct 04 '18 14:10

Adam Price


1 Answers

In my experience, this happens when I end up with NAs for my labels. I'm willing to bet your 'variable' variable has NAs instead of the strings you are wanting for col= argument in your call to ggplot. I also noticed you have col= twice both in and outside aes which could be problematic. I just ran into this using Shiny, and thought I would offer my 2 cents.

like image 73
roberty boberty Avatar answered Oct 31 '22 17:10

roberty boberty