ggTimeSeries
ggTimeSeries copied to clipboard
Plotting "N/A" year when no values for that year exist
There are no NA values in the dataset, however this is plotting an N/A year.
require(ggTimeSeries)
#> Loading required package: ggTimeSeries
#> Loading required package: ggplot2
require(tidyverse)
#> Loading required package: tidyverse
x <- structure(list(year = c(2017, 2017, 2017, 2017, 2017, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018),
date = structure(c(17479, 17480, 17483,
17505, 17528, 17534, 17569, 17581, 17591, 17611, 17639, 17640,
17644, 17655, 17694, 17701, 17702, 17704, 17709, 17714, 17715,
17735), class = "Date"),
n = c(23L, 22L, 24L, 5L, 19L, 2L, 5L,
10L, 5L, 6L, 13L, 2L, 1L, 6L, 2L, 13L, 1L, 32L, 17L, 1L, 3L,
14L)),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -22L))
x
#> # A tibble: 22 x 3
#> year date n
#> <dbl> <date> <int>
#> 1 2017 2017-11-09 23
#> 2 2017 2017-11-10 22
#> 3 2017 2017-11-13 24
#> 4 2017 2017-12-05 5
#> 5 2017 2017-12-28 19
#> 6 2018 2018-01-03 2
#> 7 2018 2018-02-07 5
#> 8 2018 2018-02-19 10
#> 9 2018 2018-03-01 5
#> 10 2018 2018-03-21 6
#> # ... with 12 more rows
x %>%
ggTimeSeries::ggplot_calendar_heatmap(cDateColumnName = "date", cValueColumnName = "n") +
facet_grid(year ~ .)
Created on 2018-08-13 by the reprex package (v0.2.0).
As a workaround for now, you can use the vcGroupingColumnNames
argument, rename your column to Year
from year
.
This happens because https://github.com/AtherEnergy/ggTimeSeries/blob/a6233974af05e2cea3535c17d47082f1dc7fef2e/R/ggplot_calendar_heatmap.R#L98 adds NAs to the year column.
That bit of code is required because the lines separating the days, weeks, etc. are also drawn as part of the plot and they need to know which year, etc. they need to fall in which is why I calcualte year inside the function anyway. I confess, this isn't the most friendly or best written of functions.
I can think of some ideas to help make this more flexible -
-
Allow a choice of colour, transparency for missing values.
-
Allow a choice of layout for the facetting.
Any others you can think of?