简体   繁体   中英

How I can create a function for create a plot with echarts4r?

Hello everyone and good night. I would like to know if it is possible to create a function to simplify the creation of a chart with Echarts4r in r. Im trying but I get the error Error: Can't subset columns that don't exist. . Anyone knows how I can fix it? The code im using is the following:

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)

Use the functions e_charts_ and e_bar_ and pass the column names as character.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM