gpt4 book ai didi

r - 更改顶点边框的线类型

转载 作者:行者123 更新时间:2023-12-01 23:40:42 25 4
gpt4 key购买 nike

有没有办法用 R 更改 igraph 图中顶点边框的线型?例如,我想用虚线而不是实线制作顶点。

更新:以下是生成带有黑色边框的节点的示例代码。我想知道是否有办法使黑色边框成为虚线黑色边框(如标准 R 线图中的“lty = 2”):

library('igraph')
NodeList = data.frame('AA', x = 1 ,y = 1)
EdgeList = data.frame(from = 'AA', to = 'AA')
xgraph = graph_from_data_frame(vertices = NodeList,
d = EdgeList, directed = TRUE)
plot(xgraph, vertex.shape = 'circle',
vertex.size = 100, rescale = FALSE)

最佳答案

哎呀,无论如何我都会发布它。毕竟是代码。这要归功于 Gabor Csardi 和@user20650。我认为引文处于足够稳定的位置,我们可以预期在未来几年内可以访问它。 :

png(width=200,height=200)
mycircle <- function(coords, v=NULL, params) {
vertex.color <- params("vertex", "color")
if (length(vertex.color) != 1 && !is.null(v)) {
vertex.color <- vertex.color[v]
}
vertex.frame.lty <- params("vertex", "lty")
if (length(vertex.frame.lty) != 1 && !is.null(v)) {
vertex.frame.lty <- vertex.frame.lty[v]
}
vertex.size <- 1/200 * params("vertex", "size")
if (length(vertex.size) != 1 && !is.null(v)) {
vertex.size <- vertex.size[v]
}
vertex.frame.color <- params("vertex", "frame.color")
if (length(vertex.frame.color) != 1 && !is.null(v)) {
vertex.frame.color <- vertex.frame.color[v]
}
vertex.frame.width <- params("vertex", "frame.width")
if (length(vertex.frame.width) != 1 && !is.null(v)) {
vertex.frame.width <- vertex.frame.width[v]
}
mapply(coords[,1], coords[,2], vertex.color, vertex.frame.color,
vertex.size, vertex.frame.width, vertex.frame.lty,
FUN=function(x, y, bg, fg, size, lwd, lty) {
symbols(x=x, y=y, bg=bg, fg=fg, lwd=lwd, lty=lty,
circles=size, add=TRUE, inches=FALSE)
})
}
dev.off()

add.vertex.shape("fcircle", clip=igraph.shape.noclip,
plot=mycircle, parameters=list(vertex.frame.color=1, vertex.frame.lty=1,
vertex.frame.width=1))

plot(xgraph, vertex.shape="fcircle", vertex.frame.color="red", vertex.size=100 ,vertex.lty=2,
vertex.frame.width=2)

有警告称,如果 igraph API 发生更改,这可能无法保证正常工作:

enter image description here

关于r - 更改顶点边框的线类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48725525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com