ggvis
ggvis copied to clipboard
layer_rects for multiple rectangles
I want to plot my data using layer_lines. I also want to be able to draw some blocks/rectangles over the final product. So I decided to use layer_rects, is that a correct approach?
If, so how can I add multiple rectangles to the plot by using one layer_rects? So lets say if I want to add 100 rectangles I don't want to have something like this 100 times:
layer_rects(x = ~ 100, x2 = ~ 200, y = ~ -0.02, y2 = ~ 0.02,) %>%
Here is my code: stats <- # some data I want to plot... rects <- data.frame(x1 = runif(2), x2 = runif(2), y1 = runif(2), y2 = runif(2)) # The rectangles I want to put on the plot
stats %>%
ggvis(~time, ~value, stroke = ~variable) %>%
layer_lines(strokeWidth := 1) %>%
layer_rects(x = ~rects$x1, x2 = ~rects$x2, # This causes an error
y = ~rects$y1, y2 = ~rects$y2,
opacity := 0.01, fill := "grey") %>%
bind_shiny("ggvis", "ggvis_ui")
Currently it breaks: Length of calculated column 'rects$x1' (2) is not equal to 1 or the number of rows in data. How can I fix it? I might have N lines to show using the stats data but I want to have M rectangles independently.
Thanks!
@baniani see here for providing a reproducible example. Perhaps, you have not received an answer so far is because of not providing a reproducible example, that others could emulate, to see what you want to achieve, and help you with the same.