如何解决ggplotly中的rangeslider:滑块的开始和结尾不起作用
我想将rangeslider()
与ggplotly()
一起使用。不幸的是,定义滑块的开始和结束不适用于ggplotly()
。我在RShiny应用程序的server.R中使用rangeslider()
。在服务器中,它看起来像以下代码片段:
output$maForwardVsSpotPLOT <- renderPlotly({
plotFvsS <- MAForwardVsSpotMeanDifference(input$maStrategy,input$maTradingDays,input$maDateRange[1],input$maDateRange[2],input$maPeriod)$FvsSMeanDiffPlot
ggplotly(plotFvsS,dynamicTicks = TRUE) %>%
rangeslider() %>% # start = input$maDateRange[1],end = input$maDateRange[2]
layout(hovermode = "x")
})
在用户界面中,我有:
tabItem(tabName = "maForwardVsSpot",fluidRow(width = 7,dateRangeInput(inputId = "maFFDateRange",label = "Date Range",start = "2018-01-01",end = Sys.Date()),plotlyOutput(outputId = "maForwardVsSpotPLOT",width = "900px",height = "600px")
plotFvsS是在外部函数(MAForwardVsSpotMeanDifference
)中定义的,看起来像这样:
plotFvsS <- ggplot(dt.allDataFvsS,aes(x = date,y = meanDifference)) +
coord_cartesian(ylim = c(-25,25)) + # Note: using ylim throws all data outside of ylim away!!! using coord_cartesian solves this problem
ggtitle("Price Difference Forward vs. Spot") +
geom_line(color = "blue",size = 0.9) +
labs(y = "EUR/MWh",x = "Date") +
theme(axis.text = element_text(size = 9),axis.title = element_text(size = 5),panel.grid.minor = element_blank(),panel.grid.major = element_blank(),panel.border = element_rect(fill = NA,color = "black",size = 1)) +
theme_bw(base_size = 17) +
theme(panel.grid.minor = element_blank(),panel.grid.major = element_blank()) +
geom_hline(yintercept = 0,color = "black") +
geom_hline(yintercept = c(20,10,-10,-20),color = "#CCCCCC") +
geom_vline(xintercept = c(12481,12784,13149,13514,13879,14245,14610,14975,15340,15706,16071,16436,16801,17167,17532,17897,18262,18628)) +
geom_vline(xintercept = c(12509,12600,12692,12874,12965,13057,13239,13330,13422,13604,13695,13787,13970,14061,14153,14335,14426,14528,14700,14791,14883,15065,15156,15248,15431,15522,15614,15796,15887,15979,16161,16252,16344,16526,16617,16709,16892,16983,17075,17257,17348,17440,17622,17713,17987,18078,18170,18353,18444,18536),linetype = "dashed",color = "#666666") +
geom_vline(xintercept = 17805,color = "red")
如何在rangeslider()
中添加开始和结束?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。