我正在尝试使用r plotly绘制具有以下功能的图表:
一个图表中有2个Y轴的2个线图:一个在左边,另一个在右边
Date Amount1 Amount2
2/1/2017 19251130 21698.94
2/2/2017 26429396 10687.37
2/5/2017 669252 0.00
2/6/2017 25944054 11885.10
2/7/2017 27895562 14570.39
2/8/2017 20842279 20080.56
2/9/2017 25485527 9570.51
2/10/2017 17008478 14847.49
2/11/2017 172562 0.00
2/12/2017 379397 900.00
2/13/2017 25362794 18390.80
2/14/2017 26740881 11490.94
2/15/2017 20539413 22358.26
2/16/2017 22589808 12450.45
2/17/2017 18290862 3023.45
2/19/2017 1047087 775.00
2/20/2017 4159070 4100.00
2/21/2017 28488401 22750.35
我使用的代码是:
ay <- list(
#tickfont = list(color = "red"),
overlaying = "y",
side = "right"
)
p <- plot_ly() %>%
add_lines(x = df$Date, y = df$Amount1, name = "Amount1",type = "scatter", mode = "lines") %>%
add_lines(x = df$Date, y = df$Amount2, name = "Amount2", yaxis = "y2",type = "scatter", mode = "lines") %>%
layout(
title = "Chart Summary", yaxis2 = ay,
xaxis = list(title="Date")
)
输出图表看起来很好,但X轴上的日期间隔看起来很糟糕。我想知道这是什么解决方案,如果我想使用上面的数据在一个图表中有2个直方图,那么最佳方法是什么?
谢谢你的帮助!