我希望将我的图例放在图内,就像这个问题中所回答的那样,但是针对一个交互式图。
在第一个代码块中,图例离开了绘图区域,但是当我去掉交互时它正常工作。
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)
)))
如何在交互式图中叠加图例?