【发布时间】:2020-10-05 22:50:37
【问题描述】:
我正在尝试在三个 groups 之间创建一个加权 scatterplot。
例子:
library(ggplot2)
df <- data.frame("groups" = c('AA','BB','CC', 'AA','BB','CC', 'AA','BB','CC'),
"something" = c('aaaaaa', 'bbbbb', 'cccccc', 'dddddddd', 'eeeeeee', 'ffffffff', 'gggggggggg', 'hhhhhhhhh', 'iiiiiiiii'),
"value1" = c(1.1, 2.4, 3.5, 5, 4.1, 3, 2.5, 1.4, 4.5),
"value2" = c(2, 25, 10, 4, 15, 5, 3, 4, 8))
我已尝试使用以下代码绘制加权散点图并获得类似于Scatter.14 from here 的输出。
ggplot(data = df, aes(x = groups, y = something, size = value1, color = -log10(value2)))+
geom_point()+
scale_color_gradientn(colors = rainbow(4))+
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
我在运行上述代码时不断收到错误消息。
Error in farver::decode_colour(colors, alpha = TRUE, to = "lab", na_value = "transparent") :
unused argument (na_value = "transparent")
sessionInfo() 是这样的:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.2
loaded via a namespace (and not attached):
[1] withr_2.1.2 dplyr_1.0.2 crayon_1.3.4 grid_3.6.1
R6_2.4.1 lifecycle_0.2.0
[7] gtable_0.3.0 magrittr_1.5 scales_1.1.1 pillar_1.4.3
rlang_0.4.7 farver_2.0.1
[13] rstudioapi_0.11 generics_0.0.2 vctrs_0.3.4 ellipsis_0.3.0
tools_3.6.1 glue_1.4.2
[19] purrr_0.3.4 munsell_0.5.0 compiler_3.6.1 pkgconfig_2.0.3
colorspace_1.4-1 tidyselect_1.1.0
[25] tibble_3.0.3
Is there any way to fix this error? Or if there is a better approach?
【问题讨论】:
-
我无法重现您的错误 - 我的情节看起来不错。您能否在主要问题中包含
sessionInfo()的输出,以便我们知道您使用的是什么版本的ggplot。 -
是的,它工作正常。尝试重新启动
R并仅加载ggplot2。好像和其他包有冲突! -
是的,我尝试重新启动
R并仅加载ggplot2包。它仍然给我一个错误。我将在我的问题中编辑并发布sessionInfo()。