'for' loop and 'lists' in plotly - R

Viewed 15

I want to add some shapes to my chart:

    p <- p %>% layout(shapes = list(list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_1,  x0 = x0_1,  x1 = x1_1,  xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
                                    list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_2,  x0 = x0_2,  x1 = x1_2,  xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
                                    list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_3,  x0 = x0_3,  x1 = x1_3,  xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
                                    list(type = "rect", fillcolor = kolorrecesji, line = list(color = kolorrecesji), opacity = op_4,  x0 = x0_4,  x1 = x1_4,  xref = "x", y0 = min_y, y1 = max_y, yref = "y"),
    ...

Can I have dynamic number od these shapes? I prefer to have shapes in data frame with different x0, x1, fillcolor and opacity (or parameter permitting to draw or not) and use for ... loop rather than list them one by one like above?

rgds & thks

Grzegorz

0 Answers
Related