【问题标题】:What is causing "Must request at least one colour from a hue palette" error in my R package only on linux-based builds?是什么导致我的 R 包中的“必须从色调调色板中请求至少一种颜色”错误仅在基于 linux 的版本上?
【发布时间】:2019-03-10 00:37:25
【问题描述】:

我目前正在检查一些代码的跨平台兼容性。我在 GitHub 提交上使用 Travis-CI 在 ubuntu 下构建我的 R 包。如果我消除这一个部分,它会成功构建,但如果我包含此代码,我会收到错误:

Must request at least one colour from a hue palette.

这构建良好并且在 Windows 和 OS X 上正常工作,这个问题只出现在 ubutu 构建上。我还想指出,这是在执行以下代码的小插图构建步骤期间发生的。此错误消息似乎来自this function in the R scales library.

我有一些看起来像这样的数据:

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

我是用ggplot2来显示这个数据的,我的命令大概如下:

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")

这是触发错误的部分。我觉得这个问题可能是 aes() 或 scale_fill_manual() 的一些小技术问题。我试图看看以几种不同的方式改变这些是否有任何影响,但因为我使用的是 Travis-CI,所以每次更改后都需要相当长的时间进行测试。

是否有人看到可能导致问题的原因或对为什么会发生这种情况有任何见解?提前非常感谢。

编辑:我想指出我已将问题缩小到这段代码。

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

如果我执行以下操作,它会起作用,但我的颜色会丢失。

geom_point()

EDIT2:我已修改数据部分以使其更有用。现在应该直接复制/粘贴单词。

【问题讨论】:

  • 如果您粘贴代码的方式可以直接复制并粘贴到 R 终端并工作,那么重现您的示例会更容易。
  • @Prevost 我已经更新了数据部分。现在应该可以复制/粘贴了。
  • 您是否知道您使用ggplot(data = filteredList) 作为您的ggplot 数据,而您的实际dataframe 被命名为filteredDatafilteredList 在您的示例代码中不存在。
  • @Prevost 是的,只是我在制作示例数据时打错了字。
  • @AdamPrice 你能提供一个指向你的 GitHub 存储库的链接吗?您在此处发布的代码在我运行 Ubuntu 18.04 的机器上运行没有错误

标签: r ubuntu ggplot2 compiler-errors r-package


【解决方案1】:

根据我的经验,当我最终为我的标签使用 NA 时,就会发生这种情况。我愿意打赌您的“变量”变量具有 NA,而不是您在调用 ggplot 时需要 col= 参数的字符串。我还注意到你在 aes 内外都有 col= 两次,这可能是有问题的。我刚刚使用 Shiny 遇到了这个问题,并认为我会提供我的 2 美分。

【讨论】:

  • 我遇到了同样的问题,这个答案解决了它
猜你喜欢
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多