How do I control the axis labels on a ggvis plot where the variables to be plotted are selected interactively?

独自空忆成欢 提交于 2020-01-07 05:03:28

问题


I am trying to create an interactive visualization with the ggvis package.

Specifically, the user should be able to select which of the variables should be plotted on which axes. One way to do this was already presented in answer 2 of this question. However in this solution the axes are not labeled correctly:

E.g. in this example

library("ggvis")
library("magrittr")
sel <- input_select(names(mtcars),map=as.name)
mtcars %>% ggvis(sel,~mpg) %>% layer_points()

The y-axis has a label of "reactive_x" (x being a random number). I would now like to label the y-axis according to the currently selected variable. Adding

%>% add_axis("y",title=sel)

does not work because sel is a closure, not a character vector. Wrapping sel in as.character does not work either.

Does anybody have a solution to this problem?

Note: This would possibly easier to solve by wrapping the ggvis plot in a shiny app. However, I am not interested in such solutions as this visualization will be part of a package that I am developing.

来源:https://stackoverflow.com/questions/32464822/how-do-i-control-the-axis-labels-on-a-ggvis-plot-where-the-variables-to-be-plott

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!