R中作为x轴标签的图标

阿尔贝托

我想绘制这样的内容(本文),其中图标(在这种情况下为小图形)用作刻度标签。

在此处输入图片说明

我到这里为止,或多或少正确放置了图标:在此处输入图片说明这是代码:

library(igraph)    
npoints <- 15
y <- rexp(npoints)
x <- seq(npoints)

par(fig=c(0.05,1,0.3,1), new=FALSE)
plot(y, xlab=NA, xaxt='n',  pch=15, cex=2, col="red")
lines(y, col='red', lwd=2)

xspan <- 0.9
xoffset <- (0.07+0.5/npoints)*xspan
for(i in 1:npoints){  
  x1 <- (xoffset+(i-1)/npoints)*xspan
  x2 <- min(xspan*(xoffset+(i)/npoints),1)
  par(fig=c(x1,x2,0,0.5), new=TRUE)
  plot(graph.ring(i), vertex.label=NA)  
}

但是,如果点数增加(例如npoints <- 15),则会抱怨,因为图标没有位置:

Error in plot.new() : figure margins too large

我想知道是否还有一种更自然的方法可以使它适用于任何(合理)点数。

欢迎任何建议。

饼干面包师
library(igraph)    
npoints <- 15
y <- rexp(npoints)
x <- seq(npoints)

# reserve some extra space on bottom margin (outer margin)
par(oma=c(3,0,0,0))
plot(y, xlab=NA, xaxt='n',  pch=15, cex=2, col="red")
lines(y, col='red', lwd=2)

# graph numbers 
x = 1:npoints   

# add offset to first graph for centering
x[1] = x[1] + 0.4
x1 = grconvertX(x=x-0.4, from = 'user', to = 'ndc')
x2 = grconvertX(x=x+0.4, from = 'user', to = 'ndc')

# abline(v=1:npoints, xpd=NA)
for(i in x){  

  print(paste(i, x1[i], x2[i], sep='; '))

  # remove plot margins (mar) around igraphs, so they appear bigger and 
  # `figure margins too large' error is avoided
  par(fig=c(x1[i],x2[i],0,0.2), new=TRUE, mar=c(0,0,0,0))
  plot(graph.ring(i), vertex.label=NA)  

  # uncomment to draw box around plot to verify proper alignment:
  # box()

}

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章