dyShading R dygraph

妖精的绣舞 提交于 2019-11-29 00:37:45

For example:

#create dygraph
dg <- dygraph(nhtemp, main = "New Haven Temperatures")

#add shades
for( period in ok_periods ) {
  dg <- dyShading(dg, from = period$from , to = period$to )
}

#show graph
dg

If you have periods in a list:

ok_periods <- list(
  list(from = "1920-1-1", to = "1930-1-1"),
  list(from = "1940-1-1", to = "1950-1-1"),
  list(from = "1960-1-1", to = "1970-1-1")
)

Using pipe

If you want to use pipe, you could define a new function

add_shades <- function(x, periods, ...) {
  for( period in periods ) {
    x <- dyShading(x, from = period$from , to = period$to, ... )
  }
  x
}

and use it in a chain:

dygraph(nhtemp, main = "New Haven Temperatures") %>% 
  add_shades(ok_periods, color = "#FFFFCC" )
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!