Does anyone know if it is possible to change the variables for the x and y axis interactively with ggvis? I can change the size of the data points, their position and opacit
You could also build the plot into a shiny reactive function that swaps the axes. There may be a flash when ggvis redraws the plot, but it will have the effect you're looking for.
This modifies the code from ideamotor, above; I also altered it to use the reactive function rather than reactive data as the input to ggvis, which allows ggvis to ... oh, just try it, you'll see:
library(shiny);library(ggvis)
shinyServer(function(input, output) {
plotData <- reactive({
df <- iris[,c("Sepal.Width",input$yVariable,"Species")]
names(df) <- c("x","y","fill")
df
})
reactive({
plt <- **plotData** %>% ggvis(fill=~fill) %>%
add_legend("fill", title = "Species")
if (**input$someCheckBox**) {
plt <- plt %>%
layer_points(x = ~x, y = ~y) %>%
add_axis("x", title = "Sepal.Width") %>%
add_axis("y", title = input$yVariable)
} else {
plt <- plt %>%
layer_points(x = ~y, y = ~x) %>%
add_axis("y", title = "Sepal.Width") %>%
add_axis("x", title = input$yVariable)
}
plt
}) %>% bind_shiny("ggvisPlot")
})