如何在交互式ggvis中将变量名称作为轴标签传递?

时间:2016-10-29 19:33:04

标签: r ggvis

此代码生成我想要的图表,但我希望将input_radiobuttons的内容作为垂直轴标签代替随机字符串reactive_931110099

enter image description here

library(ggvis)
mtcars %>% ggvis(x = ~wt, y= input_radiobuttons( 
     choices = c("mpg" = 'mpg', "disp" = 'disp'),
      label = "Y-axis",
      map = as.name)
     )
    layer_densities(
      adjust = input_slider(.1, 2, value = 1, step = .1, label = "Bandwidth adjustment"),
      kernel = input_select(
        c("Gaussian" = "gaussian",
          "Epanechnikov" = "epanechnikov",
          "Rectangular" = "rectangular",
          "Triangular" = "triangular",
          "Biweight" = "biweight",
          "Cosine" = "cosine",
          "Optcosine" = "optcosine"),
        label = "Kernel")
    )

1 个答案:

答案 0 :(得分:1)

mtcars %>% ggvis(x = ~wt, y= input_radiobuttons( 
     choices = c("mpg" = 'mpg', "disp" = 'disp'),
      label = "Y-axis",
      map = as.name)
     ) %>%
   add_axis("y", title = "Pick Your Own Label", title_offset = 50)
    layer_densities(
      adjust = input_slider(.1, 2, value = 1, step = .1, label = "Bandwidth adjustment"),
      kernel = input_select(
        c("Gaussian" = "gaussian",
          "Epanechnikov" = "epanechnikov",
          "Rectangular" = "rectangular",
          "Triangular" = "triangular",
          "Biweight" = "biweight",
          "Cosine" = "cosine",
          "Optcosine" = "optcosine"),
        label = "Kernel")
    )

enter image description here