Ответ 1
Это, безусловно, взлом, но отлично работает:
df4 %>% ggvis(x=~x,y=~y,stroke=~id) %>% layer_lines() %>%
#make sure you use add relative scales
add_relative_scales() %>%
#values for x and y need to be between 0 and 1
#e.g for the x-axis 0 is the at far-most left point and 1 at the far-right
add_legend("stroke", title = "Cylinders", values = c(1, 1),
properties = legend_props(
legend = list(
x = scaled_value("x_rel", 0.2),
y = scaled_value("y_rel", -.2)
))) %>%
add_legend("stroke", title = " ", values = c(2, 2),
properties = legend_props(
legend = list(
x = scaled_value("x_rel", 0.23),
y = scaled_value("y_rel", -.2)
))) %>%
layer_points(x=~x,y=~y,data = df1,stroke:='black')
В принципе, я добавляю еще один add_legend
, устанавливая заголовок как пустым, настраивая scale_value
так, чтобы он был очень близок к первой легенде, но не перекрывался. Затем я устанавливаю первую легенду с values = c(1,1)
, а второй - с values = c(2,2)
, чтобы эти два значения складывались друг над другом. Это делает его похожим на одну легенду с горизонтальными значениями.