r - 如何使用 R 个性化时间线?

标签 r timeline

我想用 R 绘制一个时间线,其中的时间段很容易识别,我可以在其中个性化可视化:

  • 期间
  • 句号“盒子”的颜色
  • 线条(颜色,位置)
  • 文本的位置并将其放入“框”
  • 轴(大小,颜色,选择重点)
  • 事件日期

  • 我使用时间轴库,但是我找不到如何对其进行个性化。任何建议或其他图书馆?

    输出如下所示:

    enter image description here

    我的 R 代码是这样的:
    require(timeline)
    f <- "~/Documents/periods.csv"
    crono <- read.delim(f, header=TRUE)
    f <- "~/Documents/events.csv"
    events <- read.delim(f, header=TRUE)
    draw <- function() {
       timeline(crono, events,
         text.size = 8,
         text.color = "black",
         num.label.steps = 2,
         event.label.method = 1,
         event.text.size = 7,
         event.label = '',
         event.line = TRUE,
         event.above = FALSE)
         }
    
    png("~/Documents/Timeline.png", width = 1200, 
          height = 800, units = "px", bg = "transparent", res = NA)
    draw()
    dev.off()
    

    这是我的数据。一系列时间段:
    Name                        Group   Start_year  End_year
    First long period            long         1800      1899
    Second period               short         1870      1910
    Another long period          long         1900      1990
    More events on period time  short         1965      1985
    

    以及同时发生的一些事件:
    Event                   year
    Person 1 was born       1870
    Person 1 first novel    1895
    Build the new building  1905
    Death person 1          1930
    renovation building     1950
    collection              1970
    

    最佳答案

    使用包 vistime ,您可以个性化框的颜色(如果您在数据框中添加“颜色”列或告诉 vistimecol.colors ='yourColourColumnName' ,您可以添加工具提示并分配到组( col.groups = )。
    您可以生成 plotly-Timelines、highcharter-Timelines 或 ggplot2-Timelines,它们都是可个性化的。

    install.packages("vistime")
    library(vistime)
    crono <- read.csv(text="Name,Group,start_year,end_year
                                First long period,long,1800-01-01,1899-12-31
                                Second period,short,1870-01-01,1910-12-31
                                Another long period,long,1900-01-01,1990-12-31  
                                More events on period time,short,1965-01-01,1985-12-31")
    events <- read.csv(text="Name,start_year
                                Person 1 was born,1870-01-01
                                Person 1 first novel,1895-01-01
                                Build the new building,1905-01-01
                                Death person 1,1930-01-01
                                renovation building,1950-01-01
                                collection,1970-01-01")
    events$end_year <- NA
    events$Group <- "Events"
    
    # or gg_vistime, or hc_vistime
    vistime(rbind(crono, events), 
            col.start  = "start_year", 
            col.end = "end_year", 
            col.event = "Name", 
            col.group = "Group")
    
    enter image description here
    更多关于个性化的信息:https://shosaco.github.io/vistime/

    关于r - 如何使用 R 个性化时间线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32447483/

    相关文章:

    呈现具有不成比例的轴值的交互式时间轴的 JavaScript 库?

    r - 从 rle() 类对象列表中绘制多个直方图

    javascript - 循环遍历日期数组并使用 javascript/jQuery 标记 10 年范围

    r - ggplot2 中的轴标签消失了

    r - 用置信区间在 ggplot 中绘制月平均温度

    javascript - 在 Javascript 中构建类似布局的时间轴网格?

    twitter - 关注用户时的时间线重构

    ios - 如何创建在每日和每周基准的时间线 View 中显示日历事件的应用程序?

    r - 是否有一个函数可以查找字符向量中的所有小写字母?

    RSelenium 背后的代理