Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dput(ejemplo)
- structure(list(Año = c(2013L, 2014L, 2014L, 2014L, 2014L, 2014L,
- 2014L, 2014L, 2014L, 2014L), Mes = c(12L, 1L, 5L, 5L, 8L, 9L,
- 10L, 10L, 10L, 11L), Evento = c("Aprobación ", "Instrucción",
- "Solicitud uno", "Solicitud dos", "Creación de organismo", "Elección de administrador",
- "Aprobación dos", "Constitución comité", "Constitución organización",
- "Salida del programa"), Fecha = structure(c(16040, 16071, 16191,
- 16191, 16283, 16314, 16344, 16344, 16344, 16375), class = "Date"),
- Actor = c("Jefe", "Consejo", "Organismo", "Secretaría", "Tribunal",
- "Organismo", "Tribunal", "Consejo", "Organismo", "Organismo"
- )), class = "data.frame", row.names = c(NA, -10L))
- Actor_levels <- c("Jefe",
- "Consejo", "Organismo", "Secretaría",
- "Tribunal")
- Actor_colors <- c("#FF69B4","#0070C0", "#00B050", "#FFC000", "#C00000",
- ordered=TRUE)
- ejemplo$Actor <- factor(ejemplo$Actor, levels=Actor_levels)
- positions <- c(0.5, -0.5, 1.0, -1.0, 1.5, -1.5)
- directions <- c(1, -1)
- line_pos <- data.frame(
- "Fecha"=unique(ejemplo$Fecha),
- "position"=rep(positions, length.out=length(unique(ejemplo$Fecha))),
- "direction"=rep(directions, length.out=length(unique(ejemplo$Fecha)))
- )
- df <- merge(x=ejemplo, y=line_pos, by="Fecha", all = TRUE)
- df <- df[with(df, order(Fecha)), ]
- df
- text_offset <- 0.05
- df$month_count <- ave(df$Mes==df$Mes, df$Mes, FUN=cumsum)
- df$text_position <- (df$month_count * text_offset * df$direction) + df$position
- df
- month_buffer <- 2
- month_date_range <- seq(min(df$Fecha) - months(month_buffer), max(df$Fecha) + months(month_buffer), by='month')
- month_format <- format(month_date_range, '%B')
- month_df <- data.frame(month_date_range, month_format)
- year_date_range <- seq(min(df$Fecha) - months(month_buffer), max(df$Fecha) + months(month_buffer), by='year')
- year_date_range <- as.Date(
- intersect(
- ceiling_date(year_date_range, unit="year"),
- floor_date(year_date_range, unit="year")
- ), origin = "1970-01-01"
- )
- year_format <- format(year_date_range, '%Y')
- year_df <- data.frame(year_date_range, year_format)
- timeline_plot<-ggplot(df,aes(x=Fecha,y=0, col=Actor, label=Evento))
- timeline_plot<-timeline_plot+labs(col="")
- timeline_plot<-timeline_plot+scale_color_manual(values=Actor_colors, labels=Actor_levels, drop = FALSE)
- timeline_plot<-timeline_plot+theme_classic()
- timeline_plot<-timeline_plot+geom_hline(yintercept=0,
- color = "black", size=0.3)
- timeline_plot<-timeline_plot+geom_segment(data=df[df$month_count == 1,], aes(y=position,yend=0,xend=Fecha), color='black', size=0.2)
- timeline_plot<-timeline_plot+geom_point(aes(y=0), size=3)
- timeline_plot<-timeline_plot+theme(axis.line.y=element_blank(),
- axis.text.y=element_blank(),
- axis.title.x=element_blank(),
- axis.title.y=element_blank(),
- axis.ticks.y=element_blank(),
- axis.text.x =element_blank(),
- axis.ticks.x =element_blank(),
- axis.line.x =element_blank(),
- legend.position = "bottom"
- )
- timeline_plot<-timeline_plot+geom_text(data=month_df, aes(x=month_date_range,y=-0.1,label=month_format),size=2.5,vjust=0.5, color='black', angle=90)
- timeline_plot<-timeline_plot+geom_text(data=year_df, aes(x=year_date_range,y=-0.2,label=year_format, fontface="bold"),size=2.5, color='black')
- timeline_plot<-timeline_plot+geom_text(aes(y=text_position,label=Evento),size=2.5)
- print(timeline_plot)
- Warning message:
- Removed 10 rows containing missing values (geom_point).
- timeline_plot<-timeline_plot+geom_point(aes(y=0), size=3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement