+ - 0:00:00
Notes for current slide
Notes for next slide

Review of the second day’s material

Luke Johnston

1 / 15

Version control with Git

2 / 15

Using Git, basic workflow

  • Version control is really important, but also difficult
  • Repository is all the files in a folder tracked by Git and saved as history in .git/
  • Files that are "tracked" will have changes recorded in history (when committed)
  • Commit small changes and commit often
3 / 15

Using Git, basic workflow

  • Version control is really important, but also difficult
  • Repository is all the files in a folder tracked by Git and saved as history in .git/
  • Files that are "tracked" will have changes recorded in history (when committed)
  • Commit small changes and commit often
  1. Start tracking new files (git add and git commit; "Stage" then "Commit")
  2. Check "status" of repository (git status, in Git tab)
  3. Add and commit modified files (git add and git commit; "Stage" then "Commit")
  4. Check what was recently done to the repo (git log; "History" tab in Git Interface)
  5. Synch with GitHub, if set up (git push to upload, git pull to download; "Push" or "Pull")
3 / 15

Data visualization with ggplot2

4 / 15

Final exercise: Code to create first plot

NHANES %>%
filter(!is.na(Diabetes)) %>%
ggplot(aes(y = BMI, x = Poverty,
colour = Diabetes)) +
geom_point(alpha = 0.4) +
geom_smooth(size = 2, method = "gam") +
facet_grid(cols = vars(SurveyYr),
rows = vars(Gender)) +
scale_color_viridis_d(end = 0.8) +
theme_classic() +
theme(
strip.background = element_blank(),
panel.background =
element_rect(fill = "grey95"),
axis.line =
element_line(colour = "grey80")
)

5 / 15

Final exercise: Remove NA and set base plot

NHANES %>%
filter(!is.na(Diabetes)) %>%
ggplot(aes(y = BMI, x = Poverty,
colour = Diabetes)) +
geom_point(alpha = 0.4) +
geom_smooth(size = 2, method = "gam") +
facet_grid(cols = vars(SurveyYr),
rows = vars(Gender)) +
scale_color_viridis_d(end = 0.8) +
theme_classic() +
theme(
strip.background = element_blank(),
panel.background =
element_rect(fill = "grey95"),
axis.line =
element_line(colour = "grey80")
)

6 / 15

Final exercise: Add points and smooth geoms

NHANES %>%
filter(!is.na(Diabetes)) %>%
ggplot(aes(y = BMI, x = Poverty,
colour = Diabetes)) +
geom_point(alpha = 0.4) +
geom_smooth(size = 2, method = "gam") +
facet_grid(cols = vars(SurveyYr),
rows = vars(Gender)) +
scale_color_viridis_d(end = 0.8) +
theme_classic() +
theme(
strip.background = element_blank(),
panel.background =
element_rect(fill = "grey95"),
axis.line =
element_line(colour = "grey80")
)

7 / 15

Final exercise: Add column by row facets

NHANES %>%
filter(!is.na(Diabetes)) %>%
ggplot(aes(y = BMI, x = Poverty,
colour = Diabetes)) +
geom_point(alpha = 0.4) +
geom_smooth(size = 2, method = "gam") +
facet_grid(cols = vars(SurveyYr),
rows = vars(Gender)) +
scale_color_viridis_d(end = 0.8) +
theme_classic() +
theme(
strip.background = element_blank(),
panel.background =
element_rect(fill = "grey95"),
axis.line =
element_line(colour = "grey80")
)

8 / 15

Final exercise: Add colour scheme and set theme

NHANES %>%
filter(!is.na(Diabetes)) %>%
ggplot(aes(y = BMI, x = Poverty,
colour = Diabetes)) +
geom_point(alpha = 0.4) +
geom_smooth(size = 2, method = "gam") +
facet_grid(cols = vars(SurveyYr),
rows = vars(Gender)) +
scale_color_viridis_d(end = 0.8) +
theme_classic() +
theme(
strip.background = element_blank(),
panel.background =
element_rect(fill = "grey95"),
axis.line =
element_line(colour = "grey80")
)

9 / 15

Final exercise: Code to create second plot

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

10 / 15

Final exercise: Remove NA and set base

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

11 / 15

Final exercise: Add boxplot geom

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

12 / 15

Final exercise: Add column facets

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

13 / 15

Final exercise: Add colour scheme and set theme

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

14 / 15

Final exercise: Flip the x and y axes

NHANES %>%
filter(!is.na(Diabetes),
!is.na(Education)) %>%
ggplot(aes(x = Education,
colour = Diabetes,
y = TotChol)) +
geom_boxplot(fill = "grey90",
outlier.size = 0.5,
size = 0.75) +
facet_grid(cols = vars(Gender)) +
scale_color_brewer(type = "qual") +
theme_minimal() +
labs(y = "Total Cholesterol") +
coord_flip()

15 / 15

Version control with Git

2 / 15
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow