Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2015 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ecfe94e09cd63a70b119 to your computer and use it in GitHub Desktop.
Save anonymous/ecfe94e09cd63a70b119 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(dplyr)
library(magrittr)
library(tidyr)
rec.cum <- read.table('clipboard', h = TRUE, stringsAsFactors = F)
dados <- rec.cum %>%
rename(Rastreamento = r3,
Recrutamento = r25) %>%
gather(Tipo, Data, Rastreamento, Recrutamento) %>%
filter(!(Tipo == 'Recrutamento' & r24 == 'Não')) %>%
group_by(Tipo) %>%
mutate(Data = as.Date(Data),
n = 1:n())
minmax <- dados %>%
summarize(min = min(Data),
max = max(Data))
ggplot(dados, aes(Data, n, col = Tipo)) +
geom_point(aes(shape = Tipo), size = 4) +
geom_line(linetype = 'dashed', size = 1) +
labs(x = '', y = 'Número de pacientes rastreados/recrutados') +
theme_bw() + theme(legend.position = 'top') +
annotate("text", x = as.Date('2014-07-01'), y = 13,
label = paste("Primeiro recrutado: ",
filter(minmax, Tipo == 'Recrutamento')$min,
"\nÚltimo recrutado: ",
filter(minmax, Tipo == 'Recrutamento')$max)) +
annotate("text", x = as.Date('2015-01-01'), y = 7,
label = paste("Primeiro rastreado: ",
filter(minmax, Tipo == 'Rastreamento')$min,
"\nÚltimo rastreado: ",
filter(minmax, Tipo == 'Rastreamento')$max))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment