我正在尝试使用 r 创建一个图表区域图表 . 到目前为止,我有两种颜色 . 我有两个区域用于实际值,一个用于建模值 . 因此,如果建模区域超出实际值,则应显示红色,如果下降,则应为绿色 . (例如:https://bl.ocks.org/mbostock/raw/3894205/

以下是我的代码

library(dplyr)
library(plotly
        )
ab <-tibble::tribble(
  ~modeled, ~actuals, ~weekenddate,  ~err,
  501384,   481864, "2014-02-02", 19519,
  488933,   479078, "2014-02-09",  9856,
  484191,   464026, "2014-02-16", 20165,
  480443,   460339, "2014-02-23", 20104,
  482512,   464021, "2014-03-02", 18491,
  488843,   462458, "2014-03-09", 26385,
  481864,   491864, "2014-04-02", 19519,
  481864,   501864, "2014-04-09",  9856,
  464026,   480443, "2014-04-16", 20165,
  460339,   484191, "2014-04-23", 20104,
  464021,   488933, "2014-05-02", 18491,
  464021,   501384, "2014-05-09", 26385,
  501384,   481864, "2014-06-02", 19519,
  488933,   479078, "2014-06-09",  9856,
  484191,   464026, "2014-06-16", 20165,
  480443,   460339, "2014-06-23", 20104,
  482512,   464021, "2014-07-02", 18491,
  488843,   462458, "2014-07-09", 26385,
)

diff_charts <- plot_ly(x = ~ab$weekenddate, y = ~ab$modeled, type = 'scatter', mode = 'none', name = 'Modeled', fill = 'tozeroy',
                       fillcolor = 'rgba(255,0,0, 0.5)') %>%
  add_trace(x = ~ab$weekenddate, y = ~ab$actuals, name = 'Actuals', fill = 'tozeroy',
            fillcolor = 'rgba(0,255,0, 0.5)') %>%
  layout(xaxis = list(title = 'Carat'),
         yaxis = list(title = 'Density'))

diff_charts

另外,我如何在一定范围之后获得图表以清楚地看到变化 .