-
Notifications
You must be signed in to change notification settings - Fork 10
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
Including an option for a shadow for all data #105
Comments
Can this be done using a regular facet? (facet_wrap, facet_grid) Because it seems it should generally be an argument for these functions too. I just found an example, its messy, though: |
I quite like the appeal of this! I think it helps demonstrate more clearly what However, I'm not sure the best way to go about it, as (I think?) it involves adding another geom layer - while I think in most cases I would expect people to use Another option could be to overwrite the fill/colour/alpha argument to be the variable matching which facet it is in. However I guess that will override whatever the use might have set for that, which perhaps isn't the worst thing? |
Yeah, I see now this is hard to implement. |
I'd like to keep it open to consider a way around this though, even if there are some other functions, I think it is possible. |
I think this should not be implemented in |
(Apologies ahead this is long) library(brolgar)
library(tidyverse)
set.seed(1)
# * I need to have it as tsibble for it to work otherwise it produces error
# * can't people define the key in the facet_sample as an option?
# * Why the dependency on tsibble?
# People should have choice to use data.frame, tibble or tsibble? Most of tidyverse works with data.frame and tibble, not just the latter. Shouldn't broglar be the same?
df <- ChickWeight %>%
as_tsibble(key = Chick, index = Time, regular = FALSE)
ggplot(df, aes(Time, weight, group = Chick)) +
# hmm this doesn't work as expected with facet_sample
geom_line(data = mutate(df, Chick2 = Chick),
aes(group = Chick2), color = "gray") +
geom_line() +
facet_sample() The shadow got sampled too. # without brolgar
## no randomisation & no n_per_facet below
## but does the shadow trick as expected
ChickWeight %>%
mutate(facet_group = as.numeric(Chick) %% 12 + 1 ) %>%
ggplot(aes(Time, weight, group = Chick)) +
geom_line(data = rename(ChickWeight, Chick2 = Chick), # trick to repeat in each facet
aes(group = Chick2), color = "gray") +
geom_line() +
facet_wrap(~facet_group) Created on 2020-11-02 by the reprex package (v0.3.0.9001) Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.1 (2020-06-06)
#> os macOS Catalina 10.15.7
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_AU.UTF-8
#> ctype en_AU.UTF-8
#> tz Australia/Melbourne
#> date 2020-11-02
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> anytime 0.3.9 2020-08-27 [1] CRAN (R 4.0.2)
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.0)
#> backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.2)
#> blob 1.2.1 2020-01-20 [2] CRAN (R 4.0.0)
#> brolgar * 0.0.6.9100 2020-10-30 [1] Github (njtierney/brolgar@28e95bb)
#> broom 0.7.0 2020-07-09 [1] CRAN (R 4.0.2)
#> cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.0.0)
#> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [2] CRAN (R 4.0.0)
#> curl 4.3 2019-12-02 [2] CRAN (R 4.0.0)
#> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.2)
#> dbplyr 1.4.4 2020-05-27 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> distributional 0.2.1 2020-10-06 [1] CRAN (R 4.0.2)
#> dplyr * 1.0.1 2020-07-26 [1] Github (tidyverse/dplyr@16647fc)
#> ellipsis 0.3.1 2020-05-15 [2] CRAN (R 4.0.0)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.0)
#> fabletools 0.2.1 2020-09-03 [1] CRAN (R 4.0.2)
#> fansi 0.4.1 2020-01-08 [2] CRAN (R 4.0.0)
#> farver 2.0.3.9000 2020-07-24 [1] Github (thomasp85/farver@f1bcb56)
#> forcats * 0.5.0 2020-03-01 [2] CRAN (R 4.0.0)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.0.2 2018-11-29 [2] CRAN (R 4.0.0)
#> ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.0)
#> haven 2.3.1 2020-06-01 [2] CRAN (R 4.0.0)
#> highr 0.8 2019-03-20 [2] CRAN (R 4.0.0)
#> hms 0.5.3 2020-01-08 [2] CRAN (R 4.0.0)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> jsonlite 1.7.1 2020-09-07 [1] CRAN (R 4.0.2)
#> knitr 1.29 2020-06-23 [1] CRAN (R 4.0.2)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
#> lubridate 1.7.9 2020-06-08 [2] CRAN (R 4.0.1)
#> magrittr 1.5 2014-11-22 [2] CRAN (R 4.0.0)
#> mime 0.9 2020-02-04 [2] CRAN (R 4.0.0)
#> modelr 0.1.8 2020-05-19 [2] CRAN (R 4.0.0)
#> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.0)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.1)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.0)
#> purrr * 0.3.4 2020-04-17 [2] CRAN (R 4.0.0)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.0)
#> readr * 1.3.1 2018-12-21 [2] CRAN (R 4.0.0)
#> readxl 1.3.1 2019-03-13 [2] CRAN (R 4.0.0)
#> reprex 0.3.0.9001 2020-08-08 [1] Github (tidyverse/reprex@9594ee9)
#> rlang 0.4.8 2020-10-08 [1] CRAN (R 4.0.2)
#> rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.2)
#> rstudioapi 0.11 2020-02-07 [2] CRAN (R 4.0.0)
#> rvest 0.3.6 2020-07-25 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.0)
#> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.0)
#> stringi 1.4.6 2020-02-17 [2] CRAN (R 4.0.0)
#> stringr * 1.4.0 2019-02-10 [2] CRAN (R 4.0.0)
#> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.1)
#> tibble * 3.0.4 2020-10-12 [1] CRAN (R 4.0.2)
#> tidyr * 1.1.2 2020-08-27 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [2] CRAN (R 4.0.0)
#> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.2)
#> tsibble 0.9.3.9000 2020-11-01 [1] Github (tidyverts/tsibble@e749eb6)
#> vctrs 0.3.2.9000 2020-07-26 [1] Github (r-lib/vctrs@df8a659)
#> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)
#> xfun 0.16 2020-07-24 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [2] CRAN (R 4.0.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /Users/etan0038/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library |
Thinking further about this. Don't really think it's a good idea to include shadow in |
Thanks for taking the time to post this, @emitanaka ! Really appreciate you taking the time. RE
As you say, people should be able to use The reason it is only for
Some of these methods don't just sit squarely in the time series world, and so dataframe methods will be made available soon, but I won't be supporting Regarding creating the plots with the background shadow, I need to improve documentation (#106) so users can see how the facets are created and how they can avoid using Here is how to get a similar plot using the functions that power library(tsibble)
library(brolgar)
library(ggplot2)
df <- ChickWeight %>%
as_tsibble(key = Chick, index = Time, regular = FALSE)
# establish the "foreground" elements
chick_subplots <- df %>%
# number of facets * number of individuals per facet
sample_n_keys(size = 12 * 3) %>%
stratify_keys(n_strata = 12)
ggplot(df,
aes(x = Time,
y = weight,
group = Chick)) +
# plot data as background
geom_line(color = "gray") +
# plot foreground
geom_line(data = chick_subplots) +
facet_wrap(~.strata) Created on 2020-11-03 by the reprex package (v0.3.0) I'm not sure I fully agree that a facet plot that alters the data/geoms is violating the priciples of the grammar of graphics, although I think that it could potentially be a bit dangerous. @dicook pointed out to me that the I'm not even sure it's possible for the facet to detect the type of geom call used, so this Thanks for the thoughtful discussion, Emi, interested to hear your thoughts. |
One option that would be nice is to include the shadow of all data as an option for
facet_sample
orfacet_strata
. Below is not from using these facets but an example of how a few individuals are highlighted in individual facets but the grey lines show the data for all individuals. I find this "shadow" technique makes comparisons of the individuals to others easier.I also think this will be a great combination with the
facet_wrap_paginate
. This way if there are too many individuals, rather than fitting too many in one facet or choosing a select few, there is an option to print them in a separate graph with an option likepage
.The text was updated successfully, but these errors were encountered: