【问题标题】:R igraph Format Date on axis坐标轴上的 R igraph 格式日期
【发布时间】:2018-09-08 01:28:27
【问题描述】:

在下面的 igraph 中,将日期绘制为 x 轴上的标记。下面我提供了一个例子。由于日期在标签矩阵中指定,它们被格式化为原子值。如何让 x 轴上的日期以常规日期格式显示?

library(igraph)

nodes=data.frame(
  c(0,1,2,3),
  c("A","B","C","D")
)

colnames(nodes) = c("id","name")

links = data.frame(
  c(0,0,1,2),
  c(1,2,3,3)
)

colnames(links) = c("from","to")

layout = matrix(
  c(as.Date('2010-01-01'),1, as.Date('2010-01-02'),1, as.Date('2010-01-02'),2, as.Date('2010-01-06'),1), byrow = TRUE, nrow=4
)

net = graph.data.frame(links, vertices = nodes)

plot.igraph(
  net, xaxt="n",layout=layout,axes=TRUE,asp=0, rescale=FALSE,xlim=c(as.Date('2010-01-01'),as.Date('2010-01-06')),ylim=c(1,2)
)

【问题讨论】:

    标签: r date matrix plot igraph


    【解决方案1】:

    您可以按照here 的说明将轴替换为您自己的值。 使用您的代码,它给出:

    layout <- data.frame(Date = as.Date(c('2010-01-01','2010-01-02','2010-01-02','2010-01-06')), value = c(1,2,1,1))
    
    plot.igraph(
      net, 
      layout = layout, 
      rescale = FALSE,
      axis = FALSE, 
      asp = 0,
      xlim = as.Date(c('2010-01-01', '2010-01-06')),
      ylim = c(1,2)
    )
    axis(1, at = as.numeric(layout$Date), labels = layout$Date, cex.axis = 0.9)
    axis(2, at = 1:max(layout$value), labels = 1:max(layout$value))
    

    【讨论】:

    • 你的轴解释链接是你的情节,而不是帖子。
    猜你喜欢
    • 1970-01-01
    • 2013-04-06
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多