-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggplotScript.r
More file actions
38 lines (32 loc) · 1.33 KB
/
ggplotScript.r
File metadata and controls
38 lines (32 loc) · 1.33 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
library(ggplot2)
library(dplyr)
load("referralToFirstApptData.Rdata")
#Note: sample data only contained the monthly data view, original dataset contained quarterly and yearly aggregations as well
distTime <- "Monthly" ##Grouping interval for date axis
distCancerSite <- "Example"
if(distTime == "Yearly") {
tp <- "By Year"
gap <- "1 year"
label <- "%Y"
}
if(distTime == "Quarterly") {
tp <- "By Quarter"
gap <- "3 months"
label <- "%B %Y"
}
if(distTime == "Monthly") {
tp <- "By Month"
gap <- "1 month"
label <- "%B %Y"
}
dataset <- testData
dataset$SortDate <- as.Date(dataset$SortDate,format = "%d/%m/%Y")
filterset <- filter(dataset,Category == tp & Somerset_CancerSite == distCancerSite)
ggplot(filterset,aes(y = SortDate, x = DaysUntilSeen, size = PatientCount, color = DaysUntilSeen)) +
geom_point(alpha = 0.8) +
scale_size_area(max_size = 10) +
geom_vline(xintercept = 14.5, colour = "red") +
scale_colour_gradient(low="#9ebcda",high="#dd1c77") +
labs(x = "Days from Referral to 2WW Appt", y = "Referral Month", title = paste0("Days from Referral to 2WW Appt (",distCancerSite,")")) +
scale_y_date(breaks = gap,date_labels = label,limits = c(min(filterset$SortDate,na.rm = TRUE),max(filterset$SortDate,na.rm = TRUE))) +
scale_x_continuous(breaks = seq(from = 0, to = max(filterset$DaysUntilSeen,na.rm = TRUE)+2,by = 7))