Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting "N/A" year when no values for that year exist #7

Open
jzadra opened this issue Aug 13, 2018 · 1 comment
Open

Plotting "N/A" year when no values for that year exist #7

jzadra opened this issue Aug 13, 2018 · 1 comment

Comments

@jzadra
Copy link

jzadra commented Aug 13, 2018

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).

@dasather
Copy link
Collaborator

dasather commented Sep 2, 2018

As a workaround for now, you can use the vcGroupingColumnNames argument, rename your column to Year from year.

This happens because

dtDateValue <- merge(
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants