如何在一个绘图图中创建几个不同的矩形

时间:2019-05-02 10:52:07

标签: r ggplot2 plotly

我想在绘图中插入几个矩形。目前,仅绘制当前代码中的最后一个(最后一行)。我无法估计当前代码出了什么问题。

这是我当前的代码:

p <- Participant_56020 %>% plot_ly(x = ~x_mav,y = ~y_mav,frame = ~time_proxy,type = 'scatter',mode = 'lines+markers',size = 20,showlegend = F) %>% layout(yaxis = list(range = c(1000, 0))) %>% layout(xaxis = list(range = c(0, 1250))) %>%
p <- layout(p, title = 'Areas of Interest',shapes = list(list(type = "rect",fillcolor = "blue", line = list(color = "blue"),opacity = 0.3,x0 = 310, x1 = 1200, xref = "x",y0 = 0, y1 = 50, yref = "y")))
p <- layout(p, title = 'Areas of Interest',shapes = list(list(type = "rect",fillcolor = "blue", line = list(color = "blue"),opacity = 0.3,x0 = 310, x1 = 585, xref = "x",y0 = 65, y1 = 530, yref = "y")))                                                                                                                                                                                                                                                                
p <- layout(p, title = 'Areas of Interest',shapes = list(list(type = "rect",fillcolor = "blue", line = list(color = "blue"),opacity = 0.3,x0 = 310, x1 = 500, xref = "x",y0 = 550, y1 = 690, yref = "y")))                                                                                                                                                                                                                                                             
p <- layout(p, title = 'Areas of Interest',shapes = list(list(type = "rect",fillcolor = "blue", line = list(color = "blue"),opacity = 0.3,x0 = 600, x1 = 1200, xref = "x",y0 = 65 y1 = 530, yref = "y")))                                                                                                                                                                                                                                                                 x0 = 600, x1 = 800, xref = "x",
p <- layout(p, title = 'Areas of Interest',shapes = list(list(type = "rect",fillcolor = "blue", line = list(color = "blue"),opacity = 0.3,x0 = 310, x1 = 450, xref = "x",y0 = 700, y1 = 730, yref = "y"))  

这是结果图:

enter image description here

0 个答案:

没有答案