Use dygraph for R to plot xts time series by year only?
This looks like a bug in as.xts.ts
. It uses length(x)
to create the sequence of dates for the index, which returns the number of elements for a matrix (not the number of rows).
You can work around it by using as.xts
on your ts objects before calling cbind
on them.
both <- cbind(men=as.xts(men), women=as.xts(women))
Dygraph on tibble converted to xts, with 3001 series
Well, what I've accomplished after some time is that the first attempt using tbl_xts
is the right way to separate the graph in individual lines, but then I use a filter to only create columns for the cities which are contained in the shiny input. So it's now really fast :)
Like:
xtsdata <- tbl_xts(dados %>% filter(city%in%dados$city), cols_to_xts = "totalCases", spread_by = "city")
g2 <- dygraph(xtsdata, xlab='Dia', ylab='Casos (acumulado)', main="Gráfico temporal")
R timeseries jumps and plotting in dygraph
Apparently there is no solution to hide it, other than going for NA values to hide the graph itself, but the gap which still exist.
I now went for a generated timestamp misused as index to simulate the effect of an ongoing graph.
R dygraphs - plot certain content of columns
Here are some approaches:
First, use dplyr
to filter()
the data ahead of time:
library(dplyr)
apples <- data %>%
filter(Fruit == "Apple")
apples_ts <- xts(apples$Count, order.by = apples$Date)
dygraph(apples_ts)
Second, subset the data in a more traditional way ahead of time.
apples <- data[which(data$Fruit == "Apples"),]
apples_ts <- xts(apples$Count, order.by = apples$Date)
dygraph(apples_ts)
Third, subset the data in the call to xts
:
apples_ts <- xts(data[data$Fruit == "Apple",]$Count,
order.by = data[data$Fruit == "Apple",]$Date)
dygraph(apples_ts)
Fourth, write a custom function so you don't need to repeat this code for each fruit:
fruit_dygraph <- function(data, fruit) {
fruit_ts <- xts(data[data$Fruit == fruit,]$Count,
order.by = data[data$Fruit == fruit,]$Date)
dygraph(fruit_ts)
}
fruit_dygraph(data, fruit = "Apple")
Related Topics
Rcmdr Launch Error in Yosemite (Os X 10.10)
Efficient Apply or Mapply for Multiple Matrix Arguments by Row
Shade (Fill or Color) Area Under Density Curve by Quantile
Check If R Package Is Installed Then Load Library
A Way to Access Google Streetview from R
How to Retrieve the Most Repeated Value in a Column Present in a Data Frame
Unquote the Variable Name on the Right Side of Mutate Function in Dplyr
Changing Tick Intervals When X Axis Values Are Dates
Reshape Long Structured Data.Table into a Wide Structure Using Data.Table Functionality
Setting Hex Bins in Ggplot2 to Same Size
Split a Vector into Three Vectors of Unequal Length in R
Change Color Actionbutton Shiny R
Questions About Set.Seed() in R
References Truncated in Beamer Presentation Prepared in Knitr/Rmarkdown