I would like to put my legend inside the plot as answered in this question, but for an interactive plot.
In the first code chunk the legend disappears off the plot, but when I remove the interaction it works.
library(ggvis)
library(dplyr)
# With drop down list it doesn't work
mtcars %>%
ggvis(x = ~wt, y = input_select(c("Miles per gallon" = "mpg", "Horse power" = "hp", "Displacement"="disp", "Carbohydrates" = "carb"), map = as.name, selected = "mpg", label = "Variables"), fill=~cyl) %>%
layer_points() %>%
add_relative_scales() %>%
add_legend("fill", title = "Cylinders",
properties = legend_props(
legend = list(
x = scaled_value("x_rel", 0.8),
y = scaled_value("y_rel", 1)
)))
# Remove interaction and it works
mtcars %>%
ggvis(x = ~wt, y = ~mpg, fill = ~cyl) %>%
layer_points() %>%
add_relative_scales() %>%
add_legend("fill", title = "Cylinders",
properties = legend_props(
legend = list(
x = scaled_value("x_rel", 0.8),
y = scaled_value("y_rel", 1)
)))
How can I overlay the legend in an interactive plot?