Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

layer_rects for multiple rectangles #466

Open
baniani opened this issue Nov 17, 2016 · 1 comment
Open

layer_rects for multiple rectangles #466

baniani opened this issue Nov 17, 2016 · 1 comment

Comments

@baniani
Copy link

baniani commented Nov 17, 2016

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!

@duttashi
Copy link

duttashi commented Jul 4, 2017

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants