使用变量像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