当我使用全局变量作为输入时,Highchart不会绘图

问题描述 投票:0回答:1

我正在使用HighChart作为绘图工具创建一个函数。但是当我在hcaes()函数中使用全局变量时,没有任何内容被绘制。让我们使用mtcars数据集作为示例。

x = "mpg"
y = "hp"
hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))

#I am also attempting
hchart(mtcars, "point", hcaes(x = eval(x), y = eval(y), group = "cyl"))

enter image description here

#this works but, I want to use variables rather than the actual string.
hchart(mtcars, "point", hcaes(x = "mpg", y = "hp", group = "cyl"))

enter image description here

#The output I would like to see is 
 x = "mpg"
 y = "hp"
 hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))

enter image description here

r highcharts shiny shinydashboard r-highcharter
1个回答
0
投票
 x = "mpg"
 y = "hp"
 # x = enexpr(x) you may want to use that, not mandatory
 # y = enexpr(y) you may want to use that  not mandatory

 hchart(mtcars, "point", hcaes(x = !! x, y = !! y, group = "cyl"))

这段代码应该有效

© www.soinside.com 2019 - 2024. All rights reserved.