@@ -18,7 +18,7 @@ library(here)
18
18
knitr::opts_chunk$set(echo = TRUE)
19
19
20
20
consultations_gp <- read_delim(
21
- here("tutorials", "Lesson1", "data", "consultations_cleaned_2024 -08-13 .txt"),
21
+ here("inst", " tutorials", "Lesson1", "data", "consultations_cleaned_2025 -08-08 .txt"),
22
22
delim = "\t",
23
23
show_col_types = FALSE
24
24
)
@@ -59,11 +59,22 @@ my_plot1_nicer <- my_plot1 +
59
59
```
60
60
61
61
62
- ## Setup
62
+ ## Introduction and setup
63
63
64
- Load the necessary libraries
64
+ This tutorial can be followed in two ways:
65
+
66
+ - write and run the code in the boxes provided here,
67
+ - create your own project, write a script and execute.
68
+
69
+ If you choose the first option, you don't need to load the data nor libraries,
70
+ if you want the other option, download the data from
71
+ [ the source] ( https://github.com/jromanowska/RMED-ggplot-tutorial/tree/main/inst/tutorials/Lesson1/data ) ,
72
+ install and load the libraries.
73
+
74
+ We will be using {here}, {tidyverse}, and {patchwork}.
65
75
66
76
``` {r}
77
+ library(here)
67
78
library(tidyverse)
68
79
library(patchwork)
69
80
```
@@ -77,22 +88,22 @@ A plot in `ggplot2` consists of several layers:
77
88
- one row per datapoint
78
89
- all grouping must be included in the data
79
90
80
- 2 . aesthetics (` aes ` ) ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#section- aesthetics ) )
91
+ 2 . aesthetics (` aes ` ) ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#aesthetics ) )
81
92
- how to map the data to the graph?
82
93
- which column is * x* , * y* , ...
83
94
- which column provides grouping (based on the grouping, one can either connect points into lines, split a graph into several facets, or color differently each group)
84
95
85
- 3 . ` geom ` s ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#section- geoms ) )
96
+ 3 . ` geom ` s ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#geoms ) )
86
97
- how to visualize the data?
87
98
- points (` geom_point ` ), lines (` geom_line ` ), bars (` geom_bar ` ), etc.
88
99
- ` geom ` s are connected to ` stat ` s that conduct any necessary pre-processing of data (e.g., ` geom_histogram ` would first calculate the number of observations in each bin through ` stat_bin ` )
89
100
90
- 4 . ` scale ` s ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#section- scales ) )
101
+ 4 . ` scale ` s ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#scales ) )
91
102
- any type of data representation on the plot
92
103
- coordinates: ` scale_x_continuous ` , ` scale_x_discrete ` , ` scale_x_date ` , etc.
93
104
- colors: ` scale_color_manual ` , ` scale_colour_brewer ` , ` scale_fill_continuous ` , etc.
94
105
95
- 5 . ` theme ` ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#section- themes ) )
106
+ 5 . ` theme ` ([ original documentation] ( https://ggplot2.tidyverse.org/reference/index.html#themes ) )
96
107
- visual aspects
97
108
- size and types of fonts
98
109
- positioning of axes, legends, etc.
@@ -105,13 +116,18 @@ Let's read in some data.
105
116
106
117
``` {r, eval=FALSE}
107
118
consultations_gp <- read_delim(
108
- here("data", "consultations_cleaned_2024 -08-13 .txt"),
119
+ here("data", "consultations_cleaned_2025 -08-08 .txt"),
109
120
delim = "\t"
110
121
)
111
122
consultations_gp
112
123
```
113
124
114
- This is publicly available data from SSB (Norwegian Statistics Bureau) on number of consultations at general practitioners (GP) between 2012 and 2021.
125
+ ``` {r, echo=FALSE}
126
+ consultations_gp
127
+ ```
128
+
129
+
130
+ This is publicly available data from SSB (Norwegian Statistics Bureau) on number of consultations at general practitioners (GP) between 2012 and 2024.
115
131
116
132
Let's plot some numbers: total number of patients per year and per group ("diagnosis").
117
133
0 commit comments