logo
down
shadow

assign multiple color to each vertex in igraph


assign multiple color to each vertex in igraph

By : John Anderson
Date : November 22 2020, 09:00 AM
I hope this helps . (EDIT) Because the edges were specified as integers the vertices were not in order in the graph. I changed the initial graph.data.frame call to specify the order, then everything should work.
code :
g<-graph.data.frame(d,directed = F, vertices = 1:10)
# Put in vertex order
m <- m[order(m$vertex), ]

# Create a palette (any palette would do)
pal <- rainbow(n=length(unique(m$affilation)))

# Get each node's first affiliation
oneAffil <- m$affilation[!duplicated(m$vertex)]

# Assign to the vertices as a color attribute
V(g)$color <- pal[oneAffil]

plot(g)
# Use a cast to split out affiliation in each group as a column
library(reshape2)
am <- acast(m, formula = vertex ~ affilation)

# Turn this into a list
values <- lapply(seq_len(nrow(am)), function(i) am[i,])


plot(g, vertex.shape="pie", vertex.pie=values, vertex.pie.color=list(pal))


Share : facebook icon twitter icon
igraph plot conditional vertex color

igraph plot conditional vertex color


By : Bakhtiyor Begmatov
Date : March 29 2020, 07:55 AM
wish help you to fix your issue 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:
code :
V(g)$color <- ifelse(V(g)$name %in% dat[,1], "red", "blue")
plot(g)
igraph assign a vector as an attribute for a vertex

igraph assign a vector as an attribute for a vertex


By : Allchix
Date : March 29 2020, 07:55 AM
this will help I am trying to assign a vector as an attribute for a vertex, but without any luck: , This works fine:
code :
## replace c(3,1) by list(c(3,1))
g <- set.vertex.attribute(g, 'checked', 2, list(c(3, 1)))
V(g)[2]$checked
[1] 3 1
    g<-set.vertex.attribute(g, 'checked', 2, c(3, 1))
number of items to replace is not a multiple of replacement length
 length(list(c(3,1)))
[1] 1
> length(data.frame(c(3,1)))
[1] 1
How to add color to part of igraph vertex?

How to add color to part of igraph vertex?


By : robinsen
Date : March 29 2020, 07:55 AM
With these it helps I have two data files. One file contains all the date relationship like "A B", which means A has connection with B. I use this relationship to create the network with igraph. The other one has the data which I want to color these nodes in the igraph and of course all of these data exist in the first file. I wrote these codes below but I'm not sure how to color them. , You can color the nodes that are in Color.txt like this:
code :
library(igraph)
dat <- readLines(n=4)
A B
B C
D A
A C
col <- readLines(n=2)
A
B
g <- make_graph(unlist(strsplit(dat, " ", T)))
plot(g, vertex.color = V(g)$name %in% col)
Adding Color to Vertex in VisNetwork Igraph

Adding Color to Vertex in VisNetwork Igraph


By : Hiếu Trần
Date : March 29 2020, 07:55 AM
this will help You can add it as the "group" attribute of your igraph which informs the node coloring by default. Drawing on code from your other post :
code :
col = c("#80FF00FF", "#FF0000FF", "#FF0000FF", "#00FFFFFF",
          "#FF0000FF", "#8000FFFF", "#FF0000FF", "#FF0000FF",
          "#FF0000FF", "#FF0000FF")
i96e <- set.vertex.attribute(i96e, name = "group",value = col)
visIgraph(i96e, idToLabel = TRUE, layout = "layout_nicely")
Set igraph vertex color based on vertex attribute using RColorBrewer

Set igraph vertex color based on vertex attribute using RColorBrewer


By : Gopinath
Date : March 29 2020, 07:55 AM
help you fix your problem Typo? At least in my version of RColorBrewer it is brewer.pal not brewer_pal
We want to use the value of the group attribute to select a color from the palette that you generated, but those values are strings, not numbers. One way to get by this is to convert the strings to factors and then use those as numbers. That will convert each unique string value to a unique numeric value. We can use that to select the color.
code :
plot(g, vertex.color = pal[as.numeric(as.factor(vertex_attr(g, "group")))])
Related Posts Related Posts :
  • Remove same columns from left_join
  • Grouped barplot with R
  • Strange addTaskCallback work in RStudio
  • Make dual X-axs based on different variables using ggvis
  • Generate a normal distribution within certain limits in R
  • from data table, randomly select one row per group
  • ngrams not in correct order
  • ggplot: plot title and plot overlap each other
  • Display groups with different borders in histogram with panel.superpose
  • Submit form with no submit button in rvest
  • Can't download .csv from dropbox
  • How to get Adjusted R-Square value as variable?
  • Check row-wise if element exists in comma-separated column with position
  • How to know which nodes in a graph are removable
  • Generate all possible permutations of a binary matrix
  • R, Windows and foreign language characters
  • Datapusher with missing values and mixed (srting/numeric) data
  • Adding greek characters with variables to axis title
  • R - Subsetting subsets of variable names in loops
  • R dynamically naming a data frame to be used in ggplot2
  • Optimize/vectorize a loop in R that generates randoms from ranges in input vectors?
  • How to sort groups within sorted groups?
  • How to get randomForest model output in probability using Caret?
  • how to plot a data frame into R
  • Calculate mean of a range of rows
  • How to sum the values in a text file?
  • Looking up polygons in a shapefile that point belong in... why does it work with some shapefiles, not with others?
  • R creating a list using variable columns from df
  • Determine programmatically if a function call refers to your own function or a package's (or base R's) function?
  • Adding Special Characters to a plot in R
  • How to dynamically change R .libPaths() based on hostname?
  • Print arguments of a function in R
  • Creating Variables via A loop in r
  • How to randomly divide an integer into a fixed number of integers, such that the obtained tuples are uniformly distribut
  • Remove columns using column name based on levels of factors
  • What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?
  • Assigning Dates to Fiscal Year
  • conditional removal from data frame
  • Getting variables out of a function in R
  • Bar colors in ggplot2 geom_bar not applied correctly (R)
  • Create a vector in a dataframe based on matching a second vector to a row name in another object
  • Convert julian day to mm/dd and add year from another column in dataframe in r
  • Change SMOTE parameters inside CARET k-fold cross-validation classification
  • rollapply classes each segment the same
  • rename the header of the spliting group in r
  • Summary stats by factor level for multiple variables
  • Processing Rmarkdown inside chunks
  • R: how to join the duplicate rows in one dataframe
  • Creating a unified time-series, with dates coming from different (natural) languages
  • R error: attempt to apply non-function , randomForest , rfImpute
  • How do I add shading and color to the confidence intervals in ggplot 2 generated Kaplan-Meier plot?
  • How to generate spatial points with a pattern
  • ggplot2 + stat_contour variable binwidth
  • Add fake data to a data frame based on variable condition
  • Utilizing a character vector inside a function
  • match fundction with data frames that are differently constructed
  • Overlaying plots with a horizontal date in R
  • lapply'ing a for loop returns NULL
  • Dynamically add UI elements and gather their input in a dataframe in shiny
  • All the possible outcomes
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co