Reputation: 3288
Is there a way to change the line type of the border of vertex in an igraph plot with R? For example, I'd like to make vertex with a dashed edge instead of a solid line.
Update: Here is example code that produces a node with a black border. I'm wondering if there's a way to make that black border a dashed black border (like 'lty = 2' in a standard R line plot):
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)
Upvotes: 5
Views: 1257
Reputation: 263342
Oh heck, I'll post it anyway. It's code after all. The credit should go to Gabor Csardi and @user20650. I think that citation is in a sufficiently stable location that we can expect it to be accessible in future years. :
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)
There was a warning that this might not be guaranteed to work if the igraph API changes:
Upvotes: 6