Search code examples
rlegendggvis

ggvis - adjust legend color to fill color


The following code produces marks with fill colors ranging from red to yellow. the default legend however has a blue spectrum.

library(ggvis)
mtcars %>% 
ggvis(~wt, ~mpg, fill = ~disp, stroke = ~disp, strokeWidth := 2) %>%
layer_points() %>%
scale_numeric("fill", range = c("red", "yellow")) %>% 
add_legend("fill", orient = 'left')

How do I remove the default le from the top right corner?


Solution

  • The default legend is for stroke, your custom one is for fill. If you instead set stroke to "black" in the ggvis line, the legend on the right will dissappear.

    ...ggvis(~wt, ~mpg, fill = ~disp, stroke := "black", strokeWidth := 2) %>% ...
    

    enter image description here