Best technique for timelines

前端 未结 2 973
囚心锁ツ
囚心锁ツ 2021-02-06 07:42

Now that Gaddafi\'s 40+ years rule has ended, I want to construct a timeline graph of his period in power with those of other countries over the era. e.g US presidents, German c

2条回答
  •  忘掉有多难
    2021-02-06 07:54

    This is a simple task for ggplot:

    Create some data:

    x <- data.frame(
        country = rep(c("USA", "Germany"), each=2),
        boss = c("Nixon", "Ford", "Brandt", "Schmidt"),
        start = as.Date(c("1969-01-20", "1974-08-09", "1969-10-22", "1974-05-16"))
    )
    

    Make the plot:

    library(ggplot2)
    ggplot(x, aes(x=start, y=country)) + 
        geom_line() + 
        geom_point() + 
        geom_text(aes(label=boss), hjust=0, vjust=0) +
        xlim(c(min(x$start), max(x$start)+5*365)) # Add some space to right
    

    enter image description here

提交回复
热议问题