Last active
February 7, 2018 12:01
-
-
Save benapie/79a581c577910441fdbd8558bede5047 to your computer and use it in GitHub Desktop.
This is a plot for analysing the relationship between a proportion and a variable. Calculates the proportion for sets with a lower limit of a specific variable and calculates the proportions as you move the lower limit up. Even includes a count bar so you know how much data is there, graph starts at the 1st percentile and ends when the number of…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table <- tibble(Measure = numeric(), Percent = numeric(), Count = numeric()) | |
for (i in seq(main$Measure %>% quantile(0.01) %>% round(1), max(main$Measure), 0.1)) { | |
main.sub <- main %>% filter(Measure > i) | |
prop.count <- main.sub$IsCondition %>% which() %>% length() | |
count <- main.sub %>% nrow() | |
if (prop.count < 30) { | |
break | |
} | |
table <- table %>% add_row(Measure = i, | |
Percent = 100 * prop.count / count, | |
Count = count) | |
} | |
ggplot(table)+ | |
labs(title = "", | |
x = "Lower limit on Measure ()", | |
y = "Percent (%)", | |
colour = "Parameter")+ | |
geom_line(aes(Measure, | |
Percent, | |
colour = "Percent"), | |
size = 1)+ | |
geom_line(aes(Measure, | |
Count * max(table$Percent) / nrow(main), | |
colour = "Count"), | |
size = 1)+ | |
scale_y_continuous(sec.axis = sec_axis(~. * nrow(main) / max(table$Percent), | |
name = "Count")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment