botloggy
botloggy

Reputation: 403

ggplot2: Weighted scatterplot between groups

I am trying to create a weighted scatterplot between three groups.

Example:

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

I have tried the below code to plot the weighted scatterplot and get output similar to 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())

I keep getting the error when I run the above code.

Error in farver::decode_colour(colors, alpha = TRUE, to = "lab", na_value = "transparent") : 
unused argument (na_value = "transparent")

The sessionInfo() is like this:

> 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?

Upvotes: 0

Views: 238

Answers (1)

Ben Norris
Ben Norris

Reputation: 5747

Try updating your farver package. You have version 2.0.1. I have 2.0.3, and I cannot replicate your error.

Upvotes: 1

Related Questions