Reputation: 940
I'm new to R and iGraph. I'm trying to make a vertex in column position #1, appear in a specific color.
My data comes in from CSV and looks like this:
CL1920 202.80 V66.7 198.89 511.9 799.02 401.9 696.1 388.01 202.80
RM119041 331.82 294.10
RM38755 331.82 294.10 276.0 331.0 294.10
HK54701 331.82 294.10 276.0 331.0 294.10 401.9 V10.51
....
My plot script look looks something like this:
dat <- read.csv("data.csv", header =F)
g <- graph.data.frame(dat, directed = F)
colCount <- 1+ count.fields("dat.csv", sep = ",")
V(g)$label <- NA
set.seed(10)
par <- par()$mar; par(mar=rep(0, 4))
plot (g, layout = layout.fruchterman.reingold,
vertex.frame.color = "#FFFFFF",
vertex.size = 5,
edge.width = 2.5+ (log(colCount)/max(log(colCount))),
edge.color = "Grey60")
I've tried unsuccessfully to set vertex.color. Examples like this seem to default to "lightblue"
V(g)$color <- ifelse (V(g)$V1, "red", "blue")
Can someone point me in the right direction?
Upvotes: 2
Views: 4236
Reputation: 10825
So it seems (from the comments) that the goal is to set the vertex color based on whether the vertex appears in the first column of the dat
data frame. Here is a way:
V(g)$color <- ifelse(V(g)$name %in% dat[,1], "red", "blue")
plot(g)
Upvotes: 8