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