我试图提供一个带有列名的变量来创建一个plotly
图表,类似于ggplot2::aes_string
。不知怎的,我被困住了......
plot_ly(iris, x=~Sepal.Length, y=~Sepal.Width) # works as expected
plot_ly(iris, x=~'Sepal.Length', y=~'Sepal.Width') # fails since it doesn't use the column
我想这是一个非常简单的问题,但我只是错过了寻找堆栈溢出解决方案的词汇。
只是通过阅读手册(一如既往)弄清楚了......使用as.formula
效果很好。
my_x <- 'Sepal.Length'
my_y <- 'Sepal.Width'
plot_ly(iris, x=as.formula(paste0('~', my_x)), y=as.formula(paste0('~', my_y)))
但也许有更好的解决方案?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)