闪亮的ggplot意外错误

时间:2017-11-14 18:53:42

标签: r ggplot2 shiny

我正在尝试创建一个闪亮的ggplot,它响应与日期相关的用户定义输入。这似乎是一个直截了当的问题,也是我之前成功完成的问题。

在这个问题中,我在用户正在选择的dataframe weatherYear中有MODIS的值。每16个日历日是一个独特的MODIS值(例如,1月1日16日= 1,1月17日 - 2月1日= 2,等等。这显示了与我的闪亮应用程序的另一个窗口中显示的卫星图像类似时间增量的天气数据

如果我在R中使用以下代码(根据需要进行调整),并改变MODIS值,则图表会完美呈现。

output$weather <- renderPlot({
  weatherData <- filter(weatherYear, weatherYear$MODIS <= input$index)
  ggplot(weatherData, aes(x=DOY), order = DOY) +
    geom_ribbon(aes(ymin = TempMin, ymax = TempMax), alpha = 0.3, fill = "indianred2") +
    geom_line(aes(y = TempAvg), color = "black") +
    geom_bar(aes(y = Precip*20), stat = "identity", color = "blue") +
    labs(y = "Mean Daily Temperature (F)", x = "Month") +
    coord_cartesian(ylim = c(-5,105), xlim = c(1, 365)) +
    scale_y_continuous(sec.axis = sec_axis(~./20, name="Precipitation (in)")) +
    scale_x_continuous(expand = c(0, 0),
      breaks = c(15,45,75,105,135,165,195,228,258,288,320,350),
     labels = c("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"))

在闪亮的情况下,默认值1显示完美:

Shiny ggplot for default MODIS period

但是,只要选择了另一个索引周期,就会引入一个大的差距,并绘制其他未选择的索引值:

Same ggplot when MODIS index value of 2 is selected

我很难过......

0 个答案:

没有答案