R Highcharter自定义条形图功能错误

时间:2019-05-21 15:28:31

标签: r r-highcharter

我想用highcharter包创建一个自定义函数,因为我必须在工具提示发生变化的地方绘制许多条形图。

这有效:

library(dplyr)
library(highcharter)


highchart() %>%
    hc_chart(zoomType = "x") %>%
    hc_add_series(data = mtcars, type = "bar", hcaes(y = mpg))

这不是:

barchartfunction1 <- function(df, yvar) {

    highchart() %>%
        hc_chart(zoomType = "x") %>%
        hc_add_series(data = df, type = "bar", hcaes(y = yvar))
}

barchartfunction1(mtcars, yvar = mpg)

Error in mutate_impl(.data, dots) : Binding not found: yvar.
Called from: mutate_impl(.data, dots)

我非常确定这是由于Highcharter中的非标准评估造成的,所以我尝试了以下方法:

barchartfunction2 <- function(df, yvar) {

    yvar <- enquo(yvar)

    highchart() %>%
        hc_chart(zoomType = "x") %>%
        hc_add_series(data = df, type = "bar", hcaes(y = !!yvar))
}

  Column `y` is of unsupported type quoted call
Called from: mutate_impl(.data, dots)

好的,Highcharter不喜欢引用的呼叫...这是错误的方法吗?这里没有NSE?谁能帮助我解决这个问题?

0 个答案:

没有答案