0
我试图用[R plotly绘制的是具有以下特点的图表:Plotly - 剧情2 y轴的时间序列
- Date对象为X变量
2线图中的一个图表用2 Y轴:一个在左边,另一个在右边
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个直方图,那么最佳方式是什么?
谢谢你的帮忙!
谢谢!这样可行。我想我错过了,因此x轴上的刻度显示不正确。 –