-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPGMSTutorial.R
More file actions
75 lines (57 loc) · 2.36 KB
/
APGMSTutorial.R
File metadata and controls
75 lines (57 loc) · 2.36 KB
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
#Install necessary packages if they are not already installed
install.packages("dplyr")
install.packages("pxR")
install.packages("ggplot2")
install.packages("tidyr")
# Load necessary packages
library(dplyr)
library(pxR)
library(ggplot2)
library(tidyr)
# This r code was created on 2026-01-07 to accompany a release on 2026-01-21
# Set working directory to source file location
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
# Download the PX File associated with this tutorial by visiting
# data.cso.ie, searching for "GMSA04", clicking the result, then clicking "Full download"
# on the left hand side of the page and clicking "px"
# Read in px file
All.px <- read.px("GMSA04.px")
#Explore the px file metadata
All.px$TITLE
All.px$VALUES$Statistic
All.px$CODES$Anatomical.Therapeutic.Chemical.3
All.px$VALUES$Anatomical.Therapeutic.Chemical.3
All.px$VALUES$Anatomical.Therapeutic.Chemical.1
#Convert to dataframe to work with Dplyr
All.DF <- as.data.frame(All.px)
# View the DF
View(All.DF)
# YOu can ignore this code
# All.DF$HSE.Health.Regions <- "Ireland"
#Filter the dataframe for only what we're interested in
All.DF.Filtered <- All.DF%>%filter(Statistic == "Percentage of persons receiving an item from ATC1 that also received an item from ATC3" &
Sex == "All sexes" &
Age.Group == "All ages"&
Anatomical.Therapeutic.Chemical.1 == "All anatomical therapeutic chemical substances" &
Anatomical.Therapeutic.Chemical.3 == "Antidepressants (N06A)" &
HSE.Health.Regions == "Ireland"
)%>%dplyr::select(Anatomical.Therapeutic.Chemical.3, Year, value)
# View the resulting dataframe
View(All.DF.Filtered)
# Convert Year from factor to numeric for plotting
All.DF.Filtered$Year <- as.numeric(as.character(All.DF.Filtered$Year))
#plot the data
ggplot(All.DF.Filtered, aes(x = Year, y = value)) +
geom_line() +
geom_point() +
labs(
title = "Changes in Percentage of Active Persons receiving Antidepressants over time",
x = "Year",
y = "%"
) +
theme_classic()
# Save Plot
ggsave(filename = "Plot.jpeg",
width = 6, #inches
height = 4, #inches
dpi = 300) #resolution