大家好,晚安。我想知道是否有可能创建一个函数来简化在r中使用Echarts4r创建图表。我正在尝试,但我得到了错误Error: Can't subset columns that don't exist.
。有人知道我怎么修吗?我使用的代码如下:
library(echarts4r)
graf_func <- function(dataframe, vary, varx){
grafico <- base |>
e_charts(vary) |>
e_bar(varx) |>
e_tooltip(trigger = "axis")
return(grafico)
}
df <- data.frame(
var1 = runif(10, min = 100, max = 200),
var2 = runif(10, min = 10, max = 200)
)
graf_func(dataframe = df, vary = var1, varx = var2)
使用e_charts_
和e_bar_
函数并将列名作为字符传递。
library(echarts4r)
graf_func <- function(dataframe, vary, varx){
grafico <- dataframe |>
e_charts_(vary) |>
e_bar_(varx) |>
e_tooltip(trigger = "axis")
return(grafico)
}
df <- data.frame(
var1 = runif(10, min = 100, max = 200),
var2 = runif(10, min = 10, max = 200)
)
graf_func(dataframe = df, vary = "var1", varx = "var2")