Draw a chronological timeline with ggplot2

前端 未结 4 970
小蘑菇
小蘑菇 2020-12-07 23:23

I have data like

data = as.data.frame(  rbind(   c(\"1492\", \"Columbus sailed the ocean blue\"),
                                c(\"1976\", \"Americans lis         


        
4条回答
  •  清歌不尽
    2020-12-08 00:11

    Sometimes the simplest graphics are the most difficult to create in ggplot2, but it is possible (and pretty).

    data =data.frame( V1=c(1492,1976,2008),V2=c("Columbus sailed the ocean blue","Americans listened to Styx","financial meltdown"),disloc=c(-1,1,-.5))
    dev.new()
    ggplot() +
        geom_segment(aes(x = V1,y = disloc,xend = V1),data=data,yend = 0) +
        geom_segment(aes(x = 900,y = 0,xend = 2050,yend = 0),data=data,arrow = arrow(length = unit(x = 0.2,units = 'cm'),type = 'closed')) +
        geom_text(aes(x = V1,y = disloc,label = V2),data=data,hjust = 1.0,vjust = 1.0,parse = FALSE) +
        geom_point(aes(x = V1,y = disloc),data=data) +
        scale_x_continuous(breaks = c(1492,1976,2008),labels = c("1492","1976","2008")) +
        theme_bw() +
        opts(axis.text.x = theme_text(size = 12.0,angle = 90.0),axis.text.y = theme_blank(),axis.ticks = theme_blank(),axis.title.x = theme_blank(),axis.title.y = theme_blank())
    

    enter image description here

    Note: this graphic was produced entirely in the ggplot2 Plot Builder in Deducer

提交回复
热议问题