Comments (7)
Hello, good suggestion re: the width.
I'm pretty sure the irregularity of the white lines is being caused by the resolution of the saved image. If you recreate the plot in R and look at it interactively (and on a large screen) you will see the lines are evenly spaced. I will regenerate the vignettes to fix the issue.
In regards to the width argument, I will add the argument to plot.incidence2
and probably also to scale_x_incidence
. It may be sensible to default to full width (I think ggplot2 defaults to 90%) as this would avoid any issue with resolution. This should be straightforward for yrwk
, yrmon
yrqtr
but may be a little more fiddly for arbitrary periods.
For info, I've split off the logic for the grouped dates in to a separate package called grates. This package has zero strong dependencies so if you didn't want the overhead of incidence2 you may like that. It also fixes some bugs I found in the current master branch of incidence2 plus has expanded documentation on the class implementations. This week I'll be dropping the current implementation and pulling in grates as a dependency going forward.
We're closing in on the stable 1.0 release it's now just ironing out these little issues like widths etc. Hopefully within the next week or two assuming nothing urgent comes up.
from incidence2.
Thanks for the follow-up Tim, I look forward to the 1.0 release. And for sharing grates - good to know!
I've also realized that my original temporary solution of providing width = 7
to geom_col()
won't work for months, as each month has a different number of days. But it sounds like there is more complexity going on in the background with grates etc, so I hope the width 100% solution is straight-forward for you.
Thanks again,
from incidence2.
yep - when I integrate grates this should all just work by setting width = 1
as a yrwk
, yrqtr
and yrmon
will always be treated as 1 unit (see below). Using width = 1 should also work in the current master branch of incidence2
. Where it doesn't work is for arbitrary periods of time (created with as_period) but I'm hoping I can hide the additional complexity for this situation from the users.
library(grates)
library(outbreaks)
library(data.table)
library(tibble)
library(ggplot2)
# load data
dat <- as.data.table(ebola_sim_clean$linelist)
# yearweek
yearweek <- dat[, isoweek := as_yrwk(date_of_onset)
][, .(cases_new = .N), keyby = isoweek]
as_tibble(yearweek)
#> # A tibble: 56 x 2
#> isoweek cases_new
#> <yrwk> <int>
#> 1 2014-W15 1
#> 2 2014-W16 1
#> 3 2014-W17 5
#> 4 2014-W18 4
#> 5 2014-W19 12
#> 6 2014-W20 17
#> 7 2014-W21 15
#> 8 2014-W22 19
#> 9 2014-W23 23
#> 10 2014-W24 21
#> # … with 46 more rows
ggplot(yearweek, aes(isoweek, cases_new)) + geom_col(width=1) + theme_bw() + xlab("")
# yearmonth
yearmonth <- dat[, yrmon := as_yrmon(date_of_onset)
][, .(cases_new = .N), keyby = yrmon]
as_tibble(yearmonth)
#> # A tibble: 13 x 2
#> yrmon cases_new
#> <yrmon> <int>
#> 1 2014-Apr 7
#> 2 2014-May 67
#> 3 2014-Jun 102
#> 4 2014-Jul 228
#> 5 2014-Aug 540
#> 6 2014-Sep 1144
#> 7 2014-Oct 1199
#> 8 2014-Nov 779
#> 9 2014-Dec 567
#> 10 2015-Jan 427
#> 11 2015-Feb 307
#> 12 2015-Mar 277
#> 13 2015-Apr 185
ggplot(yearmonth, aes(yrmon, cases_new)) + geom_col(width=1) + theme_bw() + xlab("")
Created on 2021-03-21 by the reprex package (v1.0.0)
from incidence2.
Perfect - thank you!
Perhaps I misunderstood your reply ("Using width = 1 should also work in the current master branch of incidence2."), but I just tried using width = 1
with the current master branch of incidence2 and the argument wasn't accepted. Did I do something wrong?
# install latest master branch
pacman::p_load_current_gh("reconhub/incidence2@master")
# load data
linelist <- as.data.table(ebola_sim_clean$linelist)
# make incidence
a <- incidence2::incidence(linelist, date_of_onset, interval = "week", groups = gender)
# plot
facet_plot(a)
plot(a, width = 1) # did not work
Error was: Error in ggplot2::scale_x_continuous(..., trans = yrwk_trans(n = n, firstday = firstday)) : unused argument (width = 1)
Also, I tried to install grates but the repo was an "unknown package". I'm happy to wait till later to try your example above, but I just wanted you to know. Perhaps there are permissions? I used remotes::install_github("reconhub/grates")
from https://www.reconverse.org/grates/.
from incidence2.
Regarding grates - I've realized that it's just that "reconhub" should be "reconverse" in the install command in the README.
I got it to install with remotes::install_github("reconverse/grates")
from incidence2.
This should hopefully be fixed (as best possible) by 3361373. To see the new functionality you will need the master branch of both grates and incidence2.
When the interval is numeric, "x days", "x weeks", "month", "quarter" or "year" and you pass the argument color=NA
to plot this should now work as desired. Intervals such as "x months" (where x >= 2) are causing me trouble so I'll raise a separate issue to track this. Dense plots may still have the white line artefacts but this can hopefully be resolved by users by plotting higher resolution images.
Example:
library(outbreaks)
library(incidence2)
dat <- ebola_sim_clean$linelist
i_week_sex <- incidence(
dat,
interval = "week",
date_index = date_of_onset,
groups = gender
)
# no lines
facet_plot(i_week_sex, n_breaks = 3, color = NA)
# with lines
facet_plot(i_week_sex, n_breaks = 3)
Is this the sort of behaviour you were after?
from incidence2.
from incidence2.
Related Issues (20)
- Should we only provide getters for the variable names (not values)?
- Should a `find_peaks()` like function be in incidence HOT 1
- Restore some of the header information for incidence2 objects HOT 1
- Add minimal `new_incidence()` constructor
- Should `complete_dates()` use a different default `by` argument for POSIXct dates? HOT 7
- Consider warning when incidence objects are created with POSIXct dates HOT 1
- Error: object 'date_onset' not found HOT 1
- Error: show_cases dont work HOT 9
- reinstate `day` interval HOT 1
- Document `day` interval in vignettes.
- `plot.incidence2()` fails with `grates_period` dates HOT 3
- Make makefile more usable by others
- Ensure data.table uses 2 threads max in docs and examples
- NA values in observations cause a value of NA to be returned HOT 10
- Document how to handle grouped line list columns HOT 4
- Allow user to suppress NA warning in count variables
- vignette documentation on building upon incidence2 HOT 2
- Fix formatting of old news entries HOT 1
- Rework the devel news entry HOT 1
- 2.3.0 release TODO
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incidence2.