在R中以曲线图的折线图上用y轴标记图形

时间:2017-08-08 07:11:03

标签: r data-science

用y轴的值标记线条。我在一个中绘制了两个图形,在第一个中我根据需要得到了我的结果,但在第二个中它显示了在下轴的值

如何在x平面上显示x轴的所有值。在我的情况下,我想在x平面中显示1:18的所有值

ay <- list(
 tickfont = list(color = "red"),
 overlaying = "y",
 side = "right",
 title = "Modal price"
 )
 p <- plot_ly(M, x = ~Week, y = ~`Arrival(Tonnes)`,   
  type= "bar",mode= 'marker',
    marker = list(size = 10),name ="Weekly Arrival") %>%
  add_annotations(x = seq(1:18),
              y = M$`Arrival(Tonnes)`,
              text = M$`Arrival(Tonnes)`,
              xref = "x",
              yref = "y",
              showarrow = TRUE,

              arrowsize = .01,
              ax = 0,
              ay = -20) %>% 


     #2nd graph addition
   add_lines(x = ~Week, y = ~`Modal price`, name = "Weekly Modal  prices",   

  marker = list(size = 10), yaxis = "y2",mode="marker") %>%
           layout(
          title = "Model price vs Arrivals in Weeks", yaxis2 = ay,
          xaxis = list(title="Weeks") ) %>% 
 ##Problem here the values are not attaching with the graph continuity 

 add_annotations(x=M$Week,y=M$`Modal price`,text=M$`Modal    
   price`,xref="x",yref="y",
                showarrow=TRUE,arrowsize=0.1,ax=20,ay=-20)   

0 个答案:

没有答案