Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用变量像aes_字符串一样选择r中的轴_R_Plotly - Fatal编程技术网

使用变量像aes_字符串一样选择r中的轴

使用变量像aes_字符串一样选择r中的轴,r,plotly,R,Plotly,我试图提供一个带有列名的变量来创建一个plotly图形,类似于ggplot2::aes\u 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 我想这是一个相当简单的问题,但我只是错过了词汇表,无法

我试图提供一个带有列名的变量来创建一个
plotly
图形,类似于
ggplot2::aes\u 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)))
my_x