Search code examples
rggvis

How to change background color in ggvis?


require(ggvis)
require(dplyr)
map_data = ggplot2::map_data("world")
map_data %>% select(long, lat, group) %>%
  group_by(group) %>%
  ggvis(x = ~long, y = ~lat) %>% layer_paths(fill:="#666666") %>%
  hide_axis("x") %>% hide_axis("y")

That produces a nice map, but I'd like control over the "ocean" color (e.g. "black"). How to do that?

More generally, the ocean color is the plot default background.


Solution

  • Adding a layer_rects seems to have done it:

    require(ggvis)
    require(dplyr)
    map_data = ggplot2::map_data("world")
    minx = min(map_data$long -1)
    maxx = max(map_data$long +1)
    miny = min(map_data$lat - 1)
    maxy = max(map_data$lat + 1)
    map_data %>% select(long, lat, group) %>%
      group_by(group) %>%
      ggvis(x = ~long, y = ~lat) %>% 
      layer_rects(x=minx, x2=maxx, y=maxy, y2=miny, fill:="#000000") %>%
      layer_paths(fill:="#666666") %>%
      hide_axis("x") %>% hide_axis("y")
    

    enter image description here