Color error in ggplot2 (Error in grDevices::col2rg

2019-08-15 05:51发布

If I run:

library(ggplot2)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
bp<-ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) +
    geom_boxplot()
bp

I see the error: Error in grDevices::col2rgb(colour, TRUE) : invalid RGB specification.

If I run the identical code on my other computer, I get the expected plot. I am guessing that some plotting parameter is the culprit, but I have no idea how to find it. What's going wrong?

The computer that behaves strangely is Mac OS X 10_11_3 running R 3.2.2 via RStudio 0.99.489

标签: r ggplot2
2条回答
聊天终结者
2楼-- · 2019-08-15 06:03

Sorry I am late, but the problem is that the function alpha is masked form ggplot2, that's why if you restart R and happen to call alpha after sourcing psych but before ggplot2 it works.

Anyway, the way to solve it is to make explicit that we want the psych function:

reliability = psych::alpha(df)
查看更多
仙女界的扛把子
3楼-- · 2019-08-15 06:07

Restarting R was sufficient to fix the weird behavior. Obviously should have tried that before posting...

查看更多
登录 后发表回答