Skip to content

Commit

Permalink
Merge pull request #20 from cct-datascience/session2
Browse files Browse the repository at this point in the history
Session 2
  • Loading branch information
diazrenata authored Jun 13, 2024
2 parents d391850 + 3f9e2a4 commit 9b0024b
Show file tree
Hide file tree
Showing 32 changed files with 534 additions and 25 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
.Ruserdata

/.quarto/
/_site/
/_site/

2024/02-data-comm/measles.csv
10 changes: 10 additions & 0 deletions 2024/02-data-comm/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* how to adjust relative column with for output-location: column option. https://github.com/quarto-dev/quarto-cli/discussions/6950 */

.reveal .output6040 > div.column:first-child {
width: 60%;
vertical-align: top;
}
.reveal .output6040 > div.column:not(:first-child) {
width: 40%;
vertical-align: top;
}
6 changes: 6 additions & 0 deletions 2024/02-data-comm/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ In this session, we will introduce major principles of effective data visualizat
- Install R, RStudio, and `ggplot2`

- Some previous usage of `ggplot2`


**Materials:**

- [Script to accompany slides](script.R)
- {{< revealjs slides.html >}}
181 changes: 181 additions & 0 deletions 2024/02-data-comm/script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
library(dplyr)
library(palmerpenguins)
library(ggplot2)

# Load data

data(penguins)

penguins <- penguins |>
filter(!is.na(sex))

# Default plot

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point()

# Themes ####

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme_bw()

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme_void()

?theme_void

# Modifying theme elements ####

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank())


ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank(),
panel.grid.major = element_line(color = "black", linewidth = .5))


ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
theme(panel.grid.major = element_line(color = "black", linewidth = .5)) +
theme(panel.grid.major.x = element_line(color = "red", linewidth = .1))

# Facetting ####

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_wrap(vars(island))


ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_wrap(vars(island),
ncol = 1)


ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(island),
cols = vars(sex))

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(island),
cols = vars(sex),
switch = "y")

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(island),
cols = vars(sex),
switch = "y",
scales = "free_y")

# Modifying facet themes

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(island),
cols = vars(sex),
switch = "y") +
theme(strip.background = element_blank())

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(island),
cols = vars(sex),
switch = "y") +
theme(legend.position = "bottom")


# Counterintuitive marks and channels! ####

ggplot(penguins, aes(sex, species, size = body_mass_g)) +
geom_jitter() +
theme(panel.background = element_blank())


# Better marks and channels ####

ggplot(penguins, aes(body_mass_g)) +
geom_histogram() +
theme(panel.background = element_blank()) +
facet_grid(rows = vars(species),
cols = vars(sex),
switch = "y")

# Marks and channels options

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
shape = species)) +
geom_point() +
theme(panel.background = element_blank())

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank())

# cols4all

install.packages("cols4all", dependencies = TRUE)

library(cols4all)

c4a_gui()

ggplot(penguins, aes(body_mass_g,
bill_depth_mm,
color = species)) +
geom_point() +
theme(panel.background = element_blank()) +
scale_color_discrete_c4a_cat(palette = "carto.vivid")



# esquisse ####

install.packages("esquisse")

esquisse::esquisser(penguins)

Loading

0 comments on commit 9b0024b

Please sign in to comment.