-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2023_07_25_scurvy.qmd
117 lines (82 loc) · 2.77 KB
/
2023_07_25_scurvy.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: "Scurvy"
date: 2023-07-29
format: html
execute:
echo: true
---
# TidyTuesday
Join the R4DS Online Learning Community in the weekly #TidyTuesday event!
Every week we post a raw dataset, a chart or article related to that dataset, and ask you to explore the data.
While the dataset will be “tamed”, it will not always be tidy! As such you might need to apply various R for Data Science techniques to wrangle the data into a true tidy format.
The goal of TidyTuesday is to apply your R skills, get feedback, explore other’s work, and connect with the greater #RStats community!
As such we encourage everyone of all skills to participate!
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(tidytuesdayR)
library(scales)
theme_set(theme_light())
```
# Load the weekly Data
Download the weekly data and make available in the `tt` object.
```{r}
#| label: Load
tt <- tt_load("2023-07-25")
```
# Readme
Take a look at the readme for the weekly data to get insight on the dataset.
This includes a data dictionary, source, and a link to an article on the data.
```{r}
#| label: Readme
#| eval: interactive()
tt
```
# Glimpse Data
Take an initial look at the format of the data available.
```{r}
#| label: Glimpse
tt %>%
map(glimpse)
```
# Wrangle
Explore the data and process it into a nice format for plotting! Access each dataset by name by using a dollarsign after the `tt` object and then the name of the data set.
```{r}
#| label: Wrangle
scurvy <- tt$scurvy |>
mutate(across(ends_with("_d6"), parse_number))
```
# Visualize
Using your processed dataset, create your unique visualization.
```{r}
#| label: Visualize
p <- scurvy |>
pivot_longer(ends_with("_d6"), names_to = "category") |>
filter(category != "fit_for_duty_d6") |>
mutate(
category = category |>
str_sub(end = -4) |>
str_replace_all("_", " "),
treatment = treatment |>
str_replace_all("_", " ")
) |>
ggplot(aes(value, category)) +
geom_point(aes(color = factor(study_id)),
position = position_jitter(width = 0, height = 0.2),
show.legend = FALSE) +
facet_wrap(vars(treatment)) +
labs(x = "Severity (0 none, 1 mild, 2 moderate, 3 severe)",
y = "6 days later after treatment",
title = "Citrus was the most effective for scurvy\nin a study published by James Lind in 1757 ",
caption = "Source: medicaldata R package") +
theme(strip.background = element_rect(color = "gray50", fill = "white"),
strip.text = element_text(color = "black"),
panel.grid.minor = element_blank())
```
# Save Image
Save your image for sharing. Be sure to use the `#TidyTuesday` hashtag in your post on twitter!
```{r}
# This will save your most recent plot
ggsave("image/scurvy.png", p, width = 6, height = 4)
```