-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox.R
108 lines (95 loc) · 4.21 KB
/
sandbox.R
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
# Libraries ####
library(easypackages)
libraries("shiny","shinydashboard","tidyverse","lubridate", "plotly")
theme_set(theme_minimal())
# Dataset
medicalPractitioners <- read.csv("Data/MedicalPractitioners.csv")
medicalPractitioners$RegDate <- dmy(medicalPractitioners$RegDate)
medicalPractitioners <- medicalPractitioners %>%
select(RegDate, SPECIALTY, SUB_SPECIALTY, Qualification.Count, TOWN) %>%
rename(
`Registration Date` = RegDate,
Specialty = SPECIALTY,
`Sub Specialty` = SUB_SPECIALTY,
`Number of Qualifications` = Qualification.Count,
Town = TOWN) %>%
dplyr::mutate(Year = lubridate::year(`Registration Date`))
medicalPractitioners$`Year Range` = cut(medicalPractitioners$Year, c(1970, 1980, 1990, 2000, 2010, 2020, 2025))
levels(medicalPractitioners$`Year Range`) = c("1970-1980", "1981-1990", "1991-2000","2001-2010", "2011-2020","2021")
medicalPractitioners$`Year Range` <- factor(medicalPractitioners$`Year Range`, ordered = T, levels = c("1970-1980", "1981-1990", "1991-2000","2001-2010", "2011-2020"))
# Function for converting to Factors
to_factor <- c("Specialty","Sub Specialty","Number of Qualifications","Town")
for (col in to_factor) {
medicalPractitioners[[col]] <- as.factor(as.character(medicalPractitioners[[col]]))
}
# Plots ####
## Count of Medical Practitioners ####
medicalPractitioners %>%
group_by(`Year Range`) %>%
summarise(count = n()) %>%
ggplot(aes(`Year Range`, count)) +
geom_line(aes(group = 1),color="#aa2b1d", size=1) +
geom_point(size=4, color="#28527a") +
labs(title = "Count of Medical Practitioners in Kenya",
subtitle = "Data from 1978 to 2020",
caption = "Source: medicalboard.co.ke",
x="") +
theme(
plot.title = element_text(color = "#23689b", size = 20, face = "bold",hjust = 0.5),
plot.subtitle = element_text(color = "#161d6f", size = 13, face = "bold",hjust = 0.5),
plot.caption = element_text(color = "#0f1123", size = 10, face = "italic"),
axis.text.x = element_text(face = "bold", size = 12),
axis.text.y = element_text(face = "bold", size = 12)
) +
geom_label(aes(label=count),
nudge_x = 0.1,
nudge_y = 0.2,
size=5)
####
MPQualificationsDF <- medicalPractitioners %>%
group_by(`Year Range`, `Number of Qualifications`) %>%
summarise(count = n()) %>%
ggplot(aes(`Year Range`, count, group=`Number of Qualifications`)) +
geom_line(aes(color=`Number of Qualifications`), size=1) +
geom_point(aes(color=`Number of Qualifications`), size=5) +
labs(title = "Count of Qualifications of Medical Practitioners",
subtitle = "Data from 1978 to 2020",
caption = "Source:https://medicalboard.co.ke/DashBoard.php ",
x="") +
theme(
plot.title = element_text(color = "#23689b", size = 20, face = "bold",hjust = 0.5),
plot.subtitle = element_text(color = "#161d6f", size = 13, face = "bold",hjust = 0.5),
plot.caption = element_text(color = "#0f1123", size = 10, face = "italic"),
axis.text.x = element_text(face = "bold", size = 12),
axis.text.y = element_text(face = "bold", size = 12),
legend.title = element_blank(),
legend.position = "top"
) +
geom_label(aes(label=count),
nudge_x = 0.15,
nudge_y = 4,
size=4)
## Top Specialties in the last decade ####
SpecialtiesDF <- medicalPractitioners %>%
count(Specialty, sort = T) %>%
filter(n>20)
ggplot(SpecialtiesDF, aes(reorder(Specialty, n), n)) +
geom_col(aes(fill=Specialty)) +
coord_flip() +
labs(title = "Top Specialties of Medical Practitioners",
subtitle = "Data from 1978 to 2020",
caption = "Source:https://medicalboard.co.ke/DashBoard.php ",
x="", y="count") +
theme(
plot.title = element_text(color = "#23689b", size = 20, face = "bold",hjust = 0.5),
plot.subtitle = element_text(color = "#161d6f", size = 13, face = "bold",hjust = 0.5),
plot.caption = element_text(color = "#0f1123", size = 10, face = "italic"),
axis.text.x = element_text(face = "bold", size = 12),
axis.text.y = element_text(face = "bold", size = 12),
legend.title = element_blank(),
legend.position = "none"
) +
geom_label(aes(label=n),
nudge_x = 0.15,
nudge_y = 0.9,
size=4)