I am using !!! (splice operator/big bang operator) for ggplot2::geom_point() function, and it fails. Could someone point out what is wrong with this code? The following code tries to execute ggplot2 functions from character vectors.
library(rlang)
library(ggplot2)
data(mtcars)
data = mtcars
assoc = c( "cyl" , "hp" )
names(assoc) = c("x", "y")
assoc_lang = rlang::parse_exprs(assoc)
gg = ggplot2::ggplot(data, ggplot2::aes( ,, !!! assoc_lang )) # This works
params = c( "10", "\"black\"" )
names(params) = c("size", "colour" )
params_lang = rlang::parse_exprs(params)
gg = gg + ggplot2::geom_point( !!! params_lang ) # This fails
plot(gg)
- output
Error in !params_lang : invalid argument type
Calls: <Anonymous> -> layer
Execution halted
(NOTE) The following code is an equivalent one in an interactive manner, which shows what I want to do in the above code.
library(ggplot2)
data(mtcars)
data = mtcars
gg = ggplot2::ggplot(data, ggplot2::aes( x = cyl , y = hp ))
gg = gg + ggplot2::geom_point( size = 10, colour = "black")
plot(gg)