diff --git a/.nojekyll b/.nojekyll index 592caf2..d362b78 100644 --- a/.nojekyll +++ b/.nojekyll @@ -1 +1 @@ -752c4b0c \ No newline at end of file +ac31c849 \ No newline at end of file diff --git a/2023/02-publication-quality-figs/slides.html b/2023/02-publication-quality-figs/slides.html index ec92760..2d9bf2b 100644 --- a/2023/02-publication-quality-figs/slides.html +++ b/2023/02-publication-quality-figs/slides.html @@ -559,7 +559,7 @@

Viridis

geom_point(size = 4) v #default colors v + scale_color_viridis_c() #viridis colors -
+
@@ -592,7 +592,7 @@

Viridis variants

v + scale_color_viridis_c(option = "rocket") v + scale_color_viridis_c(option = "mako")
-
+
@@ -652,7 +652,7 @@

Viridis customization

The upper end of viridis palettes tends to be very bright yellow. You can limit the range of colors used with the begin and end arguments

v + scale_color_viridis_c()
 v + scale_color_viridis_c(begin = 0.1, end = 0.9)
-
+
@@ -749,7 +749,7 @@

Manual color palettes

scale_color_manual(values = my_cols, aesthetics = c("color", "fill"))
-
+
@@ -940,7 +940,7 @@

Custom labels

If you only want to change the axis title, you can also do that in labs()

(p2 <- p2 + labs(x = "Flipper Length (mm)", y = "Bill Length (mm)"))
 (p3 <- p3 + labs(x = "Flipper Length (mm)", y = "Bill Depth (mm)"))
-
+
@@ -1002,7 +1002,7 @@

Complete themes

There are several complete themes built-in to ggplot2, and many more available from other packages such as ggthemes.

p2 + theme_bw()
 p2 + theme_minimal()
-
+
diff --git a/2024/01-foundations/notes.pdf b/2024/01-foundations/notes.pdf index 1771be5..b28baa7 100644 Binary files a/2024/01-foundations/notes.pdf and b/2024/01-foundations/notes.pdf differ diff --git a/2024/02-data-comm/script.R b/2024/02-data-comm/script.R index 58f2028..fb8ae9c 100644 --- a/2024/02-data-comm/script.R +++ b/2024/02-data-comm/script.R @@ -179,3 +179,7 @@ install.packages("esquisse") esquisse::esquisser(penguins) + +# Measles data - not in git #### + +measles <- read.csv(here::here("2024", "02-data-comm", "measles.csv")) diff --git a/2024/03-extensions/krat.jpg b/2024/03-extensions/krat.jpg new file mode 100644 index 0000000..1aa9ccc Binary files /dev/null and b/2024/03-extensions/krat.jpg differ diff --git a/2024/03-extensions/slides.html b/2024/03-extensions/slides.html index 24e8979..c59eb3c 100644 --- a/2024/03-extensions/slides.html +++ b/2024/03-extensions/slides.html @@ -438,7 +438,10 @@

Packages

library(palmerpenguins) #for example dataset library(patchwork) #for multi-panel figures library(gridGraphics) #for combining ggplot2 and base R figures -library(gganimate) #for animated plots
+library(gganimate) #for animated plots +library(ggdist) #for showing distributions + uncertainty in data +library(dplyr) #for cleaning data +library(ggraph) #for network data
@@ -728,6 +731,395 @@

Save file

anim_save("~/Desktop/test_anim.gif")
+
+
+
+

ggdist for distributions

+
    +
  • Easily add nuance to density/histogram/ribbon plots
  • +
  • Particularly useful for: +
      +
    • Sample data
    • +
    • Fitted values + uncertainty
    • +
    • Frequentist or Bayesian parameter distributions
    • +
  • +
+
+
+

slabinterval

+
+
penguins %>%
+  ggplot(aes(x = body_mass_g, y = species)) +
+  stat_slabinterval()
+ +
+ +
+
+

Example: dotsinterval

+
+
penguins %>%
+  ggplot(aes(x = body_mass_g, y = species)) +
+  stat_dotsinterval()
+ +
+
+
+

Example: interval

+
+
penguins %>%
+  ggplot(aes(x = body_mass_g, y = species)) +
+  stat_interval()
+ +
+
+
+

Example: interval

+
+
penguins %>%
+  ggplot(aes(x = body_mass_g, y = species)) +
+  stat_interval() +
+  scale_color_brewer()
+ +
+
+
+

Combining elements: Raincloud plots

+
+
penguins %>%
+  ggplot(aes(x = body_mass_g, y = species)) +
+  stat_slabinterval() +
+  stat_dotsinterval(side = "bottom")
+ +
+
+
+

Ribbon plots

+

stat_lineribbon plots quantile intervals around a line automatically:

+
+
penguins %>%
+  ggplot(aes(x = year, y = body_mass_g)) +
+  stat_lineribbon() +
+  scale_fill_brewer() +
+  facet_wrap(vars(species))
+ +
+
+
+

Ribbon plots

+

You can control the bands using the .width argument:

+
+
penguins %>%
+  ggplot(aes(x = year, y = body_mass_g)) +
+  stat_lineribbon(.width = c(.8, .97, .99)) +
+  scale_fill_brewer() +
+  facet_wrap(vars(species))
+ +
+
+
+

Ribbon plots

+

.width = ppoints() creates a gradient:

+
+
penguins %>%
+  ggplot(aes(x = year, y = body_mass_g, fill = after_stat(.width))) +
+  stat_lineribbon(.width = ppoints(100)) +
+  scale_fill_distiller() +
+  facet_wrap(vars(species))
+ +
+
+
+

Visualizing frequentist model output

+

Combined with the broom and distributional packages, ggdist can display frequentist model uncertainty.

+
+
+

Visualizing frequentist model output

+
+
library(broom)
+library(distributional)
+
+penguin_lm <- lm(body_mass_g ~  species, data = penguins)
+
+broom::tidy(penguin_lm)
+
+
# A tibble: 3 × 5
+  term             estimate std.error statistic   p.value
+  <chr>               <dbl>     <dbl>     <dbl>     <dbl>
+1 (Intercept)        3706.       38.1    97.2   6.88e-245
+2 speciesChinstrap     26.9      67.7     0.398 6.91e-  1
+3 speciesGentoo      1386.       56.9    24.4   1.01e- 75
+
+
+
+
+

Visualizing frequentist model output

+
+
broom::tidy(penguin_lm) |>
+  ggplot(aes(y = term)) +
+    stat_halfeye(
+      aes(xdist = dist_student_t(df = df.residual(penguin_lm), 
+                                 mu = estimate, 
+                                 sigma = std.error))
+    )
+ +
+
+
+

Visualizing frequentist model output

+
    +
  • You can also use ribbons to show uncertainty around lines of fit.
  • +
  • We’ll need a linear model with a continuous predictor.
  • +
  • And we’ll use tidyr::expand and broom::augment to get the predicted line of fit from the model.
  • +
+
+
+

Visualizing frequentist model output

+
+
penguin_lm_cont <- lm(body_mass_g ~  year + species, data = penguins)
+
+penguin_lm_cont_fitted <- penguins %>%
+  group_by(species) %>%
+  tidyr::expand(year = seq(min(year), max(year), length.out = 3)) %>%
+  augment(penguin_lm_cont, newdata = ., se_fit = TRUE) 
+
+head(penguin_lm_cont_fitted) 
+
+
# A tibble: 6 × 4
+  species    year .fitted .se.fit
+  <fct>     <dbl>   <dbl>   <dbl>
+1 Adelie     2007   3703.    50.4
+2 Adelie     2008   3706.    38.2
+3 Adelie     2009   3709.    48.2
+4 Chinstrap  2007   3730.    63.6
+5 Chinstrap  2008   3733.    56.0
+6 Chinstrap  2009   3737.    64.5
+
+
+
+
+

Visualizing frequentist model output

+
+
  ggplot(penguin_lm_cont_fitted, aes(x = year)) +
+  stat_lineribbon(
+    aes(ydist = dist_student_t(df = df.residual(penguin_lm_cont), 
+                               mu = .fitted, 
+                               sigma = .se.fit))) +
+  facet_wrap(vars(species)) +
+  scale_fill_brewer() 
+ +
+
+
+

Visualizing Bayesian model components

+
    +
  • ggdist plots are great for visualizing Bayesian model components: +
      +
    • priors
    • +
    • posterior draws
    • +
    • posterior predictions
    • +
  • +
  • We can fit a simple Bayesian linear model and visualize the posterior…
  • +
+
+
+

Fitting a model

+
+
library(brms)
+library(tidybayes)
+
+penguins_brm <- brm(body_mass_g ~ species, data = penguins, iter = 1000)
+
+
+
+

Extracting draws from the posterior

+
+
penguins_brm %>%
+tidybayes::gather_draws(
+c(b_Intercept,
+b_speciesChinstrap,
+b_speciesGentoo)
+) |>
+head() 
+
+
# A tibble: 6 × 5
+# Groups:   .variable [1]
+  .chain .iteration .draw .variable   .value
+   <int>      <int> <int> <chr>        <dbl>
+1      1          1     1 b_Intercept  3646.
+2      1          2     2 b_Intercept  3680.
+3      1          3     3 b_Intercept  3694.
+4      1          4     4 b_Intercept  3688.
+5      1          5     5 b_Intercept  3632.
+6      1          6     6 b_Intercept  3779.
+
+
+
+
+

Posterior draws rainclouds

+
+
penguins_brm |>
+tidybayes::gather_draws(
+c(b_Intercept,
+b_speciesChinstrap,
+b_speciesGentoo)) %>%
+ggplot(aes(y = .variable, x = .value)) +  
+  geom_dotsinterval(side = "bottom", dotsize = .05) + 
+  stat_slabinterval() 
+ +
+
+
+

Takeaways

+
    +
  • ggdist contains geom and stat functions for plotting distributions.
  • +
  • Slab functions show variations on density plots.
  • +
  • Ribbons show variation around a line.
  • +
  • ggdist plays nicely with Bayesian and frequentist modeling frameworks.
  • +
+
+
+
+

Relational data with ggraph

+ +
+
+

ggraph

+
    +
  • For plotting networks, graphs, and trees
  • +
  • Adds layouts and geoms for nodes and edges
  • +
  • Integrates with tidygraph to wrap around numerous other graph object types (igraph, dedrogram, hclust, graph, phylo, …)
  • +
+
+
+

Example: Mouse data

+

Begin by loading network data, in this case from the graphml format.

+

Data from So et al. 2015, in the Animal Social Networks Repository.

+
+
library(igraph)
+library(tidygraph)
+
+mouse_sniffing <- read_graph(here::here("2024", "03-extensions", "mouse_so_grooming_network.graphml"),
+format = "graphml")
+
+
+
+

Example: as_tbl_graph

+

tidygraph::as_tbl_graph standardizes different graph storage formats.

+
+
mouse_graph <- mouse_sniffing |>
+as_tbl_graph() 
+
+
+
+

Plotting mouse sniffing data

+
+
ggraph(mouse_graph, layout = 'kk') + 
+    geom_edge_fan() + 
+    geom_node_point() +
+    theme_minimal() +
+    ggtitle("Mouse sniffs")
+ +
+
+
+

Alternate layouts

+
+
ggraph(mouse_graph, layout = 'eigen') + 
+    geom_edge_fan() + 
+    geom_node_point() +
+    theme_minimal() +
+    ggtitle("Mouse sniffs")
+ +
+
+
+

Alternate layouts

+
+
ggraph(mouse_graph, layout = 'linear', circular = TRUE) + 
+    geom_edge_fan() + 
+    geom_node_point() +
+    theme_minimal() +
+    ggtitle("Mouse sniffs")
+ +
+
+
+

Example: phylogenies

+
    +
  • ggraph can plot phylogenetic trees.
  • +
  • We’ll get a phylogeny using the R Open Tree of Life (rotl) and plot it.
  • +
+
+
+

Getting a phylogeny

+ +
+
+

Getting a phylogeny

+
+
library(rotl)
+rodent_id <- tnrs_match_names("Heteromyidae")
+rodent_tree <- tol_subtree(ott_id = ott_id(rodent_id))
+
+

+Progress [----------------------------------] 0/11 (  0) ?s
+Progress [================================] 11/11 (100)  0s
+                                                            
+
+
rodent_tree$node.label <- c(1:64)
+class(rodent_tree)
+
+
[1] "phylo"
+
+
+
+
+

Convert the phylogeny to a graph

+
+
rodent_graph <- as_tbl_graph(rodent_tree)
+
+
+
+

Dendrogram

+
+
ggraph(rodent_graph, "dendrogram") +
+geom_edge_link()
+ +
+
+
+

Unrooted tree

+
+
ggraph(rodent_graph, "unrooted") +
+geom_edge_link()
+ +
+
+
+

Takeaways

+
    +
  • ggraph can plot many different types of network objects.
  • +
  • Use as_tbl_graph to convert graphs to ggraph-compatible objects.
  • +
  • Layouts strongly determine the appearance and interpretability of a graph.
  • +

Extensions Resources

@@ -740,6 +1132,21 @@

Extensions Resources

  • Cheat sheet
  • Website
  • +

    ggdist

    + +
    +
    +

    Extensions Resources

    +

    ggraph

    +

    Getting Help

    @@ -748,9 +1155,15 @@

    Getting Help

  • UA Data Science Slack

  • +

    Anything we missed?

    Got a ggplot2 question we didn’t cover in this workshop series? Let’s figure it out together!

    +
    +
    +

    Data sources

    +

    Pratha Sah, José David Mendez, Shweta Bansal. A multi-species repository of social networks. Scientific Data, 6:44 (2019)

    +

    So, N., Franks, B., Lim, S., and Curley, J.P. 2015. A social network approach reveals associations between mouse social dominance and brain gene expression. PlosOne 10(7):e0134509

    @@ -758,7 +1171,7 @@

    Anything we missed?

    Intermediate ggplot2 workshop series

    - +
    diff --git a/2024/03-extensions/slides_files/figure-revealjs/slabinterval-1.png b/2024/03-extensions/slides_files/figure-revealjs/slabinterval-1.png new file mode 100644 index 0000000..97561c5 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/slabinterval-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-12-2.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-12-2.png deleted file mode 100644 index 1bdeb31..0000000 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-12-2.png and /dev/null differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-19-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-19-1.png new file mode 100644 index 0000000..41d58b2 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-19-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-20-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-20-1.png new file mode 100644 index 0000000..0c724cc Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-20-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-21-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-21-1.png new file mode 100644 index 0000000..471378c Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-21-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-22-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-22-1.png new file mode 100644 index 0000000..cc39f63 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-22-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-23-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-23-1.png new file mode 100644 index 0000000..455e563 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-23-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-24-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-24-1.png new file mode 100644 index 0000000..c47d903 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-24-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-25-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-25-1.png new file mode 100644 index 0000000..810cad2 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-25-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-27-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-27-1.png new file mode 100644 index 0000000..80cea41 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-27-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-29-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-29-1.png new file mode 100644 index 0000000..8cf9dd0 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-29-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-3-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-3-1.png index ac1af28..3fb470a 100644 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-3-1.png and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-3-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-33-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-33-1.png new file mode 100644 index 0000000..70611b5 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-33-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-36-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-36-1.png new file mode 100644 index 0000000..4f3ff74 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-36-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-37-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-37-1.png new file mode 100644 index 0000000..fbd93af Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-37-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-38-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-38-1.png new file mode 100644 index 0000000..b784526 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-38-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-1.gif b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-1.gif deleted file mode 100644 index 07657c4..0000000 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-1.gif and /dev/null differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-2.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-2.png deleted file mode 100644 index 1a9a8a3..0000000 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-4-2.png and /dev/null differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-41-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-41-1.png new file mode 100644 index 0000000..d9d56f3 Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-41-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-42-1.png b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-42-1.png new file mode 100644 index 0000000..9afdbcf Binary files /dev/null and b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-42-1.png differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-5-1.gif b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-5-1.gif deleted file mode 100644 index 07657c4..0000000 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-5-1.gif and /dev/null differ diff --git a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-6-1.gif b/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-6-1.gif deleted file mode 100644 index 33a4c05..0000000 Binary files a/2024/03-extensions/slides_files/figure-revealjs/unnamed-chunk-6-1.gif and /dev/null differ diff --git a/search.json b/search.json index 2b66996..c0edf1e 100644 --- a/search.json +++ b/search.json @@ -1361,7 +1361,7 @@ "href": "2024/03-extensions/slides.html#packages", "title": "Exploring the Wide World of ggplot2 Extensions", "section": "Packages", - "text": "Packages\n\nlibrary(ggplot2)\nlibrary(palmerpenguins) #for example dataset\nlibrary(patchwork) #for multi-panel figures\nlibrary(gridGraphics) #for combining ggplot2 and base R figures\nlibrary(gganimate) #for animated plots" + "text": "Packages\n\nlibrary(ggplot2)\nlibrary(palmerpenguins) #for example dataset\nlibrary(patchwork) #for multi-panel figures\nlibrary(gridGraphics) #for combining ggplot2 and base R figures\nlibrary(gganimate) #for animated plots\nlibrary(ggdist) #for showing distributions + uncertainty in data\nlibrary(dplyr) #for cleaning data\nlibrary(ggraph) #for network data" }, { "objectID": "2024/03-extensions/slides.html#general-use-and-modular", @@ -1510,12 +1510,243 @@ "section": "Save file", "text": "Save file\n\nanim_save(\"~/Desktop/test_anim.gif\")" }, + { + "objectID": "2024/03-extensions/slides.html#slabinterval", + "href": "2024/03-extensions/slides.html#slabinterval", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "slabinterval", + "text": "slabinterval\n\npenguins %>%\n ggplot(aes(x = body_mass_g, y = species)) +\n stat_slabinterval()\n\n\n\n\nThis plots a “halfeye” plot with a density distribution and a line at the bottom showing the mean and quantiles of the data.\nNote that we didn’t have to create any new objects; stat_slabinterval automatically calculates densities and summary statistics. There are corresponding geom_* functions for already summarized data.\nOther plot types within ggdist are variations on the stat_slabinterval theme.\nOften you’ll want to use these shortcuts instead of building something up out of scratch." + }, + { + "objectID": "2024/03-extensions/slides.html#example-dotsinterval", + "href": "2024/03-extensions/slides.html#example-dotsinterval", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: dotsinterval", + "text": "Example: dotsinterval\n\npenguins %>%\n ggplot(aes(x = body_mass_g, y = species)) +\n stat_dotsinterval()" + }, + { + "objectID": "2024/03-extensions/slides.html#example-interval", + "href": "2024/03-extensions/slides.html#example-interval", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: interval", + "text": "Example: interval\n\npenguins %>%\n ggplot(aes(x = body_mass_g, y = species)) +\n stat_interval()" + }, + { + "objectID": "2024/03-extensions/slides.html#example-interval-1", + "href": "2024/03-extensions/slides.html#example-interval-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: interval", + "text": "Example: interval\n\npenguins %>%\n ggplot(aes(x = body_mass_g, y = species)) +\n stat_interval() +\n scale_color_brewer()" + }, + { + "objectID": "2024/03-extensions/slides.html#combining-elements-raincloud-plots", + "href": "2024/03-extensions/slides.html#combining-elements-raincloud-plots", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Combining elements: Raincloud plots", + "text": "Combining elements: Raincloud plots\n\npenguins %>%\n ggplot(aes(x = body_mass_g, y = species)) +\n stat_slabinterval() +\n stat_dotsinterval(side = \"bottom\")" + }, + { + "objectID": "2024/03-extensions/slides.html#ribbon-plots", + "href": "2024/03-extensions/slides.html#ribbon-plots", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Ribbon plots", + "text": "Ribbon plots\nstat_lineribbon plots quantile intervals around a line automatically:\n\npenguins %>%\n ggplot(aes(x = year, y = body_mass_g)) +\n stat_lineribbon() +\n scale_fill_brewer() +\n facet_wrap(vars(species))" + }, + { + "objectID": "2024/03-extensions/slides.html#ribbon-plots-1", + "href": "2024/03-extensions/slides.html#ribbon-plots-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Ribbon plots", + "text": "Ribbon plots\nYou can control the bands using the .width argument:\n\npenguins %>%\n ggplot(aes(x = year, y = body_mass_g)) +\n stat_lineribbon(.width = c(.8, .97, .99)) +\n scale_fill_brewer() +\n facet_wrap(vars(species))" + }, + { + "objectID": "2024/03-extensions/slides.html#ribbon-plots-2", + "href": "2024/03-extensions/slides.html#ribbon-plots-2", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Ribbon plots", + "text": "Ribbon plots\n.width = ppoints() creates a gradient:\n\npenguins %>%\n ggplot(aes(x = year, y = body_mass_g, fill = after_stat(.width))) +\n stat_lineribbon(.width = ppoints(100)) +\n scale_fill_distiller() +\n facet_wrap(vars(species))" + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\nCombined with the broom and distributional packages, ggdist can display frequentist model uncertainty." + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-1", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\n\nlibrary(broom)\nlibrary(distributional)\n\npenguin_lm <- lm(body_mass_g ~ species, data = penguins)\n\nbroom::tidy(penguin_lm)\n\n# A tibble: 3 × 5\n term estimate std.error statistic p.value\n <chr> <dbl> <dbl> <dbl> <dbl>\n1 (Intercept) 3706. 38.1 97.2 6.88e-245\n2 speciesChinstrap 26.9 67.7 0.398 6.91e- 1\n3 speciesGentoo 1386. 56.9 24.4 1.01e- 75" + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-2", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-2", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\n\nbroom::tidy(penguin_lm) |>\n ggplot(aes(y = term)) +\n stat_halfeye(\n aes(xdist = dist_student_t(df = df.residual(penguin_lm), \n mu = estimate, \n sigma = std.error))\n )" + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-3", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-3", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\n\nYou can also use ribbons to show uncertainty around lines of fit.\nWe’ll need a linear model with a continuous predictor.\nAnd we’ll use tidyr::expand and broom::augment to get the predicted line of fit from the model." + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-4", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-4", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\n\npenguin_lm_cont <- lm(body_mass_g ~ year + species, data = penguins)\n\npenguin_lm_cont_fitted <- penguins %>%\n group_by(species) %>%\n tidyr::expand(year = seq(min(year), max(year), length.out = 3)) %>%\n augment(penguin_lm_cont, newdata = ., se_fit = TRUE) \n\nhead(penguin_lm_cont_fitted) \n\n# A tibble: 6 × 4\n species year .fitted .se.fit\n <fct> <dbl> <dbl> <dbl>\n1 Adelie 2007 3703. 50.4\n2 Adelie 2008 3706. 38.2\n3 Adelie 2009 3709. 48.2\n4 Chinstrap 2007 3730. 63.6\n5 Chinstrap 2008 3733. 56.0\n6 Chinstrap 2009 3737. 64.5" + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-5", + "href": "2024/03-extensions/slides.html#visualizing-frequentist-model-output-5", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing frequentist model output", + "text": "Visualizing frequentist model output\n\n ggplot(penguin_lm_cont_fitted, aes(x = year)) +\n stat_lineribbon(\n aes(ydist = dist_student_t(df = df.residual(penguin_lm_cont), \n mu = .fitted, \n sigma = .se.fit))) +\n facet_wrap(vars(species)) +\n scale_fill_brewer()" + }, + { + "objectID": "2024/03-extensions/slides.html#visualizing-bayesian-model-components", + "href": "2024/03-extensions/slides.html#visualizing-bayesian-model-components", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Visualizing Bayesian model components", + "text": "Visualizing Bayesian model components\n\nggdist plots are great for visualizing Bayesian model components:\n\npriors\nposterior draws\nposterior predictions\n\nWe can fit a simple Bayesian linear model and visualize the posterior…" + }, + { + "objectID": "2024/03-extensions/slides.html#fitting-a-model", + "href": "2024/03-extensions/slides.html#fitting-a-model", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Fitting a model", + "text": "Fitting a model\n\nlibrary(brms)\nlibrary(tidybayes)\n\npenguins_brm <- brm(body_mass_g ~ species, data = penguins, iter = 1000)" + }, + { + "objectID": "2024/03-extensions/slides.html#extracting-draws-from-the-posterior", + "href": "2024/03-extensions/slides.html#extracting-draws-from-the-posterior", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Extracting draws from the posterior", + "text": "Extracting draws from the posterior\n\npenguins_brm %>%\ntidybayes::gather_draws(\nc(b_Intercept,\nb_speciesChinstrap,\nb_speciesGentoo)\n) |>\nhead() \n\n# A tibble: 6 × 5\n# Groups: .variable [1]\n .chain .iteration .draw .variable .value\n <int> <int> <int> <chr> <dbl>\n1 1 1 1 b_Intercept 3646.\n2 1 2 2 b_Intercept 3680.\n3 1 3 3 b_Intercept 3694.\n4 1 4 4 b_Intercept 3688.\n5 1 5 5 b_Intercept 3632.\n6 1 6 6 b_Intercept 3779." + }, + { + "objectID": "2024/03-extensions/slides.html#posterior-draws-rainclouds", + "href": "2024/03-extensions/slides.html#posterior-draws-rainclouds", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Posterior draws rainclouds", + "text": "Posterior draws rainclouds\n\npenguins_brm |>\ntidybayes::gather_draws(\nc(b_Intercept,\nb_speciesChinstrap,\nb_speciesGentoo)) %>%\nggplot(aes(y = .variable, x = .value)) + \n geom_dotsinterval(side = \"bottom\", dotsize = .05) + \n stat_slabinterval()" + }, + { + "objectID": "2024/03-extensions/slides.html#takeaways", + "href": "2024/03-extensions/slides.html#takeaways", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Takeaways", + "text": "Takeaways\n\nggdist contains geom and stat functions for plotting distributions.\nSlab functions show variations on density plots.\nRibbons show variation around a line.\nggdist plays nicely with Bayesian and frequentist modeling frameworks." + }, + { + "objectID": "2024/03-extensions/slides.html#ggraph", + "href": "2024/03-extensions/slides.html#ggraph", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "ggraph", + "text": "ggraph\n\nFor plotting networks, graphs, and trees\nAdds layouts and geoms for nodes and edges\nIntegrates with tidygraph to wrap around numerous other graph object types (igraph, dedrogram, hclust, graph, phylo, …)" + }, + { + "objectID": "2024/03-extensions/slides.html#example-mouse-data", + "href": "2024/03-extensions/slides.html#example-mouse-data", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: Mouse data", + "text": "Example: Mouse data\nBegin by loading network data, in this case from the graphml format.\nData from So et al. 2015, in the Animal Social Networks Repository.\n\nlibrary(igraph)\nlibrary(tidygraph)\n\nmouse_sniffing <- read_graph(here::here(\"2024\", \"03-extensions\", \"mouse_so_grooming_network.graphml\"),\nformat = \"graphml\")" + }, + { + "objectID": "2024/03-extensions/slides.html#example-as_tbl_graph", + "href": "2024/03-extensions/slides.html#example-as_tbl_graph", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: as_tbl_graph", + "text": "Example: as_tbl_graph\ntidygraph::as_tbl_graph standardizes different graph storage formats.\n\nmouse_graph <- mouse_sniffing |>\nas_tbl_graph()" + }, + { + "objectID": "2024/03-extensions/slides.html#plotting-mouse-sniffing-data", + "href": "2024/03-extensions/slides.html#plotting-mouse-sniffing-data", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Plotting mouse sniffing data", + "text": "Plotting mouse sniffing data\n\nggraph(mouse_graph, layout = 'kk') + \n geom_edge_fan() + \n geom_node_point() +\n theme_minimal() +\n ggtitle(\"Mouse sniffs\")" + }, + { + "objectID": "2024/03-extensions/slides.html#alternate-layouts", + "href": "2024/03-extensions/slides.html#alternate-layouts", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Alternate layouts", + "text": "Alternate layouts\n\nggraph(mouse_graph, layout = 'eigen') + \n geom_edge_fan() + \n geom_node_point() +\n theme_minimal() +\n ggtitle(\"Mouse sniffs\")" + }, + { + "objectID": "2024/03-extensions/slides.html#alternate-layouts-1", + "href": "2024/03-extensions/slides.html#alternate-layouts-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Alternate layouts", + "text": "Alternate layouts\n\nggraph(mouse_graph, layout = 'linear', circular = TRUE) + \n geom_edge_fan() + \n geom_node_point() +\n theme_minimal() +\n ggtitle(\"Mouse sniffs\")" + }, + { + "objectID": "2024/03-extensions/slides.html#example-phylogenies", + "href": "2024/03-extensions/slides.html#example-phylogenies", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Example: phylogenies", + "text": "Example: phylogenies\n\nggraph can plot phylogenetic trees.\nWe’ll get a phylogeny using the R Open Tree of Life (rotl) and plot it." + }, + { + "objectID": "2024/03-extensions/slides.html#getting-a-phylogeny", + "href": "2024/03-extensions/slides.html#getting-a-phylogeny", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Getting a phylogeny", + "text": "Getting a phylogeny" + }, + { + "objectID": "2024/03-extensions/slides.html#getting-a-phylogeny-1", + "href": "2024/03-extensions/slides.html#getting-a-phylogeny-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Getting a phylogeny", + "text": "Getting a phylogeny\n\nlibrary(rotl)\nrodent_id <- tnrs_match_names(\"Heteromyidae\")\nrodent_tree <- tol_subtree(ott_id = ott_id(rodent_id))\n\n\nProgress [----------------------------------] 0/11 ( 0) ?s\nProgress [================================] 11/11 (100) 0s\n \n\nrodent_tree$node.label <- c(1:64)\nclass(rodent_tree)\n\n[1] \"phylo\"" + }, + { + "objectID": "2024/03-extensions/slides.html#convert-the-phylogeny-to-a-graph", + "href": "2024/03-extensions/slides.html#convert-the-phylogeny-to-a-graph", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Convert the phylogeny to a graph", + "text": "Convert the phylogeny to a graph\n\nrodent_graph <- as_tbl_graph(rodent_tree)" + }, + { + "objectID": "2024/03-extensions/slides.html#dendrogram", + "href": "2024/03-extensions/slides.html#dendrogram", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Dendrogram", + "text": "Dendrogram\n\nggraph(rodent_graph, \"dendrogram\") +\ngeom_edge_link()" + }, + { + "objectID": "2024/03-extensions/slides.html#unrooted-tree", + "href": "2024/03-extensions/slides.html#unrooted-tree", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Unrooted tree", + "text": "Unrooted tree\n\nggraph(rodent_graph, \"unrooted\") +\ngeom_edge_link()" + }, + { + "objectID": "2024/03-extensions/slides.html#takeaways-1", + "href": "2024/03-extensions/slides.html#takeaways-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Takeaways", + "text": "Takeaways\n\nggraph can plot many different types of network objects.\nUse as_tbl_graph to convert graphs to ggraph-compatible objects.\nLayouts strongly determine the appearance and interpretability of a graph." + }, { "objectID": "2024/03-extensions/slides.html#extensions-resources", "href": "2024/03-extensions/slides.html#extensions-resources", "title": "Exploring the Wide World of ggplot2 Extensions", "section": "Extensions Resources", - "text": "Extensions Resources\npatchwork\n\nPackage website\n\ngganimate\n\nCheat sheet\nWebsite" + "text": "Extensions Resources\npatchwork\n\nPackage website\n\ngganimate\n\nCheat sheet\nWebsite\n\nggdist\n\nDocumentation\nMore about tidybayes" + }, + { + "objectID": "2024/03-extensions/slides.html#extensions-resources-1", + "href": "2024/03-extensions/slides.html#extensions-resources-1", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Extensions Resources", + "text": "Extensions Resources\nggraph\n\nggraph documentation\ntidygraph documentation\nigraph R package documentation\nrotl documentation" }, { "objectID": "2024/03-extensions/slides.html#getting-help", @@ -1523,5 +1754,12 @@ "title": "Exploring the Wide World of ggplot2 Extensions", "section": "Getting Help", "text": "Getting Help\n\nOur drop-in hours\nUA Data Science Slack" + }, + { + "objectID": "2024/03-extensions/slides.html#data-sources", + "href": "2024/03-extensions/slides.html#data-sources", + "title": "Exploring the Wide World of ggplot2 Extensions", + "section": "Data sources", + "text": "Data sources\nPratha Sah, José David Mendez, Shweta Bansal. A multi-species repository of social networks. Scientific Data, 6:44 (2019)\nSo, N., Franks, B., Lim, S., and Curley, J.P. 2015. A social network approach reveals associations between mouse social dominance and brain gene expression. PlosOne 10(7):e0134509\n\n\n\n\nIntermediate ggplot2 workshop series" } ] \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index ca4ea9d..89acb80 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,66 +2,66 @@ https://cct-datascience.github.io/ggplot2-workshop-series/2024/index.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.508Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/03-extensions/index.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/02-data-comm/index.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/01-foundations/notes.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/03-extensions/slides.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/03-extensions/index.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/02-publication-quality-figs/notes.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.288Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/01-foundations/slides.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.288Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/01-foundations/index.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.288Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/02-publication-quality-figs/index.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.288Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/02-publication-quality-figs/slides.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.288Z https://cct-datascience.github.io/ggplot2-workshop-series/2023/03-extensions/notes.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/01-foundations/index.html - 2024-06-20T15:03:05.520Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/01-foundations/slides.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/02-data-comm/slides.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.292Z https://cct-datascience.github.io/ggplot2-workshop-series/2024/03-extensions/slides.html - 2024-06-20T15:03:05.524Z + 2024-06-20T16:32:20.296Z