Tutorial: Network plot from expression data in R using igraph
44
gravatar for Kevin Blighe
11 months ago by
Kevin Blighe32k
Republic of Ireland
Kevin Blighe32k wrote:

This tutorial will allow you to:

  1. create graph and tree objects from a data-frame or -matrix of numerical data
  2. identify community structure in your graph and tree objects
  3. Perform some basic downstream analyses on the tree objects

For simple testing, we'll use the estrogen microarray data-set in R and follow the tutorial from Rob Gentleman and Wolfgang Huber. This dataset was looking at genes that respond to estrogen stimulation.

The method can be applied to any type of numerical data, be it microarray, RNA-seq, metabolomics, qPCR, etc.

Step 1, Read in, normalise, and identify genes with significant effects

NB - IF YOU ALREADY HAVE YOUR OWN DATA, PROCEED TO STEP 2

[Si ya tiene sus propios datos, se va a Step 2]

[Se você já tem seus próprios dados, vá para a Step 2]

library(affy)
library(estrogen)
library(vsn)
library(genefilter)

datadir <- system.file("extdata", package="estrogen")
dir(datadir)
setwd(datadir)

#Read in the phenotype data and the raw expression 'CEL' files
pd <- read.AnnotatedDataFrame("estrogen.txt", header=TRUE, sep="", row.names=1)
a <- ReadAffy(filenames=rownames(pData(pd)), phenoData=pd, verbose=TRUE)

#Normalise the data
x <- expresso(
  a,
  bg.correct=FALSE,
  normalize.method="vsn",
  normalize.param=list(subsample=1000),
  pmcorrect.method="pmonly",
  summary.method="medianpolish"
)

#NB - if the vsn normalisation does not function, use:
#x <- expresso(a, bgcorrect.method="rma", normalize.method="constant", pmcorrect.method="pmonly", summary.method="avgdiff")

#Remove control probes
controlProbeIdx <- grep("^AFFX", rownames(x))
x <- x[-controlProbeIdx,]

#Identify genes of significant effect
lm.coef <- function(y) lm(y ~ estrogen * time.h)$coefficients
eff <- esApply(x, 1, lm.coef)
effectUp <- names(sort(eff[2,], decreasing=TRUE)[1:25])
effectDown <- names(sort(eff[2,], decreasing=FALSE)[1:25])
main.effects <- c(effectUp, effectDown)

#Filter the expression set object to include only genes of significant effect
estrogenMainEffects <- exprs(x)[main.effects,]

We now have the top 25 genes showing statistically significant effects in both directions and have filtered our expression object to include only these genes. The object that we'll use for further analysis is estrogenMainEffects

head(estrogenMainEffects)
          low10-1.cel low10-2.cel high10-1.cel high10-2.cel low48-1.cel
910_at       8.869798    8.863362     11.23440     11.12650    8.399458
31798_at    10.217214   10.121984     12.79881     12.33325   10.372707
40117_at     8.916664    8.809936     10.82381     10.72865    8.887119
1884_s_at    8.591428    8.406488     10.16884     10.33448    8.433163
947_at       9.777758    9.813295     11.72156     11.40366   10.106400
38116_at     9.126792    8.957475     11.15331     10.80998    8.152348
          low48-2.cel high48-1.cel high48-2.cel
910_at       8.400309     10.65822    10.597463
31798_at    10.112305     13.61006    13.234540
40117_at     8.669938     10.56590    10.000753
1884_s_at    8.446880     10.17888     9.533156
947_at       9.730117     11.86636    11.073517
38116_at     7.870085     10.72301    10.082670

Step 2, Create the graph and tree objects

In this example, we now have our data-frame/-matrix stored as estrogenMainEffects and will construct a graph adjacency object from this. estrogenMainEffects can be any numerical data-frame/-matrix from you own experiment(s).

library(igraph)

#Create a graph adjacency based on correlation distances between genes in  pairwise fashion.
g <- graph.adjacency(
  as.matrix(as.dist(cor(t(estrogenMainEffects), method="pearson"))),
  mode="undirected",
  weighted=TRUE,
  diag=FALSE
)

#NB - Euclidean distances can also be used instead of correlation, but this changes the tutorial slightly:
#g <- graph.adjacency(
#  as.matrix(dist(estrogenMainEffects, method="euclidean")),
#  mode="undirected",
#  weighted=TRUE,
#  diag=FALSE
#)

#Simplfy the adjacency object
g <- simplify(g, remove.multiple=TRUE, remove.loops=TRUE)

#Colour negative correlation edges as blue
E(g)[which(E(g)$weight<0)]$color <- "darkblue"

#Colour positive correlation edges as red
E(g)[which(E(g)$weight>0)]$color <- "darkred"

#Convert edge weights to absolute values
E(g)$weight <- abs(E(g)$weight)

#Change arrow size
#For directed graphs only
#E(g)$arrow.size <- 1.0

#Remove edges below absolute Pearson correlation 0.8
g <- delete_edges(g, E(g)[which(E(g)$weight<0.8)])

#Assign names to the graph vertices (optional)
V(g)$name <- V(g)$name

#Change shape of graph vertices
V(g)$shape <- "sphere"

#Change colour of graph vertices
V(g)$color <- "skyblue"

#Change colour of vertex frames
V(g)$vertex.frame.color <- "white"

#Scale the size of the vertices to be proportional to the level of expression of each gene represented by each vertex
#Multiply scaled vales by a factor of 10
scale01 <- function(x){(x-min(x))/(max(x)-min(x))}
vSizes <- (scale01(apply(estrogenMainEffects, 1, mean)) + 1.0) * 10

#Amplify or decrease the width of the edges
edgeweights <- E(g)$weight * 2.0

#Convert the graph adjacency object into a minimum spanning tree based on Prim's algorithm
mst <- mst(g, algorithm="prim")

#Plot the tree object
plot(
  mst,
  layout=layout.fruchterman.reingold,
  edge.curved=TRUE,
  vertex.size=vSizes,
  vertex.label.dist=-0.5,
  vertex.label.color="black",
  asp=FALSE,
  vertex.label.cex=0.6,
  edge.width=edgeweights,
  edge.arrow.mode=0,
  main="My first graph"
)

first

Note that layout can be modified to various other values, including:

  • layout.fruchterman.reingold
  • layout.kamada.kawai
  • layout.lgl
  • layout.circle
  • layout.graphopt

For further information, see Graph layouts


Step 3, Identify communities in the tree object based on 'edge betweenness'

mst.communities <- edge.betweenness.community(mst, directed=FALSE)
mst.clustering <- make_clusters(mst, membership=mst.communities$membership)
V(mst)$color <- mst.communities$membership + 1

par(mfrow=c(1,2))
plot(
  mst.clustering, mst,
  layout=layout.fruchterman.reingold,
  edge.curved=TRUE,
  vertex.size=vSizes,
  vertex.label.dist=-0.5,
  vertex.label.color="black",
  asp=FALSE,
  vertex.label.cex=0.6,
  edge.width=edgeweights,
  edge.arrow.mode=0,
  main="My first graph"
)

plot(
  mst,
  layout=layout.fruchterman.reingold,
  edge.curved=TRUE,
  vertex.size=vSizes,
  vertex.label.dist=-0.5,
  vertex.label.color="black",
  asp=FALSE,
  vertex.label.cex=0.6,
  edge.width=edgeweights,
  edge.arrow.mode=0,
  main="My first graph"
)

comm

Other community identification methods, including fastgreedy.community, can be found at Detecting Community Structure.


Step 4, Further analyses

#Check the vertex degree, i.e., number of connections to each vertex
degree(mst)

#Output information for each community, including vertex-to-community assignments and modularity
commSummary <- data.frame(
  mst.communities$names,
  mst.communities$membership,
  mst.communities$modularity
)
colnames(commSummary) <- c("Gene", "Community", "Modularity")
options(scipen=999)
commSummary
         Gene Community                Modularity
1      910_at         1 -0.0281615237929416124818
2    31798_at         2 -0.0086268060222194423159
3    40117_at         3  0.0117105668413069411576
4   1884_s_at         4  0.0311655447994580621363
5    38116_at         5  0.0518542468936595488116
6      947_at         6  0.0715756886160198307900
7    41400_at         4  0.0905925646858431743436
....

#Compare community structures using the variance of information (vi) metric (not relevant here)
#Community structures that are identical will have a vi=0
compare(mst.communities, mst.communities, method="vi")
[1] 0

Edit May 16, 2018: Other metrics that one can observe include:

  • hub score
  • closeness centrality
  • betweenness centrality

In a case-control study, a useful approach is to generate separate networks for cases and controls and then compare the genes in these based on these metrics.

Session info (basic)

R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS
ADD COMMENTlink modified 10 days ago • written 11 months ago by Kevin Blighe32k
1

Suggestion: add microarray tag? Also include that in the title? Or are you using the microarray data only becuase it is easily available?

ADD REPLYlink modified 11 months ago • written 11 months ago by genomax58k
1

Thanks genomax. I've added microarray and rna-seq. Technically, the method can be applied to any type of data though. I originally pieced together the pipeline on metabolomics data.

ADD REPLYlink written 11 months ago by Kevin Blighe32k
1

Thanks @ Kevin.

ADD REPLYlink written 11 months ago by cpad01129.9k

Dear @Kevin Blighe, Hi and thank you. Can I use igraph for my Trinity de novo RNA-seq assembly? I have assembled my reads then performed DEG analysis using Trinity. which file I can use as input of igraph? Thanks again.

ADD REPLYlink written 11 months ago by Farbod3.2k
1

Dear Farbod,

All that you require is a data-frame or data-matrix of numerical data, preferably binomial distributed, as the method is based on Pearson correlation.

If your data-frame/-matrix is MyData, then the starting point is:

library(igraph)

#Create a graph adjacency based on correlation distances between genes in  pairwise fashion.
g <- graph.adjacency(as.matrix(as.dist(cor(t(MyData), method="pearson"))), mode="undirected", weighted=TRUE, diag=FALSE)

You can also use Euclidean distances instead of correlation, with:

g <- graph.adjacency(as.matrix(dist(MyData, method="euclidean")), mode="undirected", weighted=TRUE, diag=FALSE)
ADD REPLYlink modified 11 months ago • written 11 months ago by Kevin Blighe32k

Thank you

Trinity produces several kind of matrix. for example the first line of "Trans_counts.TMM.EXPR.matrix" is as:

                             J1     J2        J3      M1        M2     M3

TRINITY_DN190458_c7_g4_i9    0.188   0.020   0.098   0.223   0.121   0.092

can I use that ?

ADD REPLYlink modified 11 months ago • written 11 months ago by Farbod3.2k
1

It looks fine.

The code in the tutorial above can be used in very diverse ways and the meaning/significance of the graph will change depending on the data that you provide. If you are supplying it data from Trinity, then I presume that it is de novo transcriptome assembly transcripts? The graph of these would then show transcripts whose expression is highly positively or inversely correlated.

ADD REPLYlink written 11 months ago by Kevin Blighe32k

Yes it is de novo but

Please tell me what do you mean by "ranscripts whose expression is highly positively or inversely correlated"? are you telling me that the result graph would have some sort of skew or error? or it would be just a great candidate for my data?

ADD REPLYlink written 11 months ago by Farbod3.2k
1

Hey Farbod, the tutorial first generates a square correlation matrix of your data. It answers the question: 'Which genes are highly correlated with each other?' The graph object is then created from this correlation matrix. Thus, the edges in your graph will connect genes that are highly positively or inversely correlated. Closely related genes will also be grouped together in the same community.

You should probably ask yourself this question: why do you want to perform network analysis on your data and what do you believe it will add to your project?

In the example that I provide in the tutorial, I first filter the example dataset to include only genes that are statistically significantly related to treatment group and time (n=50). The resulting plot, then, shows the potential relationships between just these significant genes.

ADD REPLYlink modified 11 months ago • written 11 months ago by Kevin Blighe32k

Thank you Kevin, I got some errors in step1 data normalization

x <- expresso(
+   a,
+   bg.correct=FALSE,
+   normalize.method="vsn",
+   normalize.param=list(subsample=1000),
+   pmcorrect.method="pmonly",
+   summary.method="medianpolish"
+ )

normalization: vsn

PM/MM correction : pmonly

expression values: medianpolish

normalizing...Error in do.call(method, alist(object, ...)) : could not find function "normalize.AffyBatch.vsn"

ADD REPLYlink written 11 months ago by Mike1.1k
1

try loading library "vsn" (library(vsn))

ADD REPLYlink written 11 months ago by cpad01129.9k

Hi Mike, did you install the vsn package? - Does library(vsn) return an error?

If you already have your own data, then you can start from the second step 'Create the graph and tree objects'

ADD REPLYlink written 11 months ago by Kevin Blighe32k

yes I installed vsn and loaded library(vsn)

then I check normalize.AffyBatch.vsn, but I couldnt get it...

?normalize.AffyBatch.vsn

normalize.AffyBatch.vsn package:vsn R Documentation

Wrapper for vsn to be used as a normalization method with expresso

Description:

 Wrapper for ‘vsn2’ to be used as a normalization method with the
 expresso function of the package affy. **The expresso function is
 deprecated, consider using ‘justvsn’ instead**. The
 normalize.AffyBatch.vsn can still be useful on its own, as it
 provides some additional control of the normalization process
 (fitting on subsets, alternate transform parameters).
ADD REPLYlink written 11 months ago by Mike1.1k
1

The normalisation method is not too important just for the tutorial. Could you try:

x <- expresso(a, bgcorrect.method="rma", normalize.method="constant", pmcorrect.method="pmonly", summary.method="avgdiff")
ADD REPLYlink written 11 months ago by Kevin Blighe32k

Thank you very much, Kevin

ADD REPLYlink written 11 months ago by Mike1.1k

Then watch out for the control probes step!

Use this instead of the original line:

main.effects <- main.effects[-which(main.effects %in% c("AFFX-CreX-3_at","AFFX-CreX-5_at"))]
ADD REPLYlink written 11 months ago by Kevin Blighe32k

Hi again Mike, I now remove those control probes just after normalisation. So, they shouldn't be a problem. I also added a note about VSN possibly not working.

Thanks for your feedback!

ADD REPLYlink written 11 months ago by Kevin Blighe32k

Hi, I have used it on my whole Trinity matrix file just for test and I received the following error:

Error in cor(t("/home/trans_counts.TMM.EXPR.matrix"),  : 
  'x' must be numeric

is it some separator issues?

ADD REPLYlink written 11 months ago by Farbod3.2k
1

You may have to read the file 'home/trans_counts.TMM.EXPR.matrix' into a data-frame? Something like

MyData <- read.table("/home/trans_counts.TMM.EXPR.matrix", sep="\t") #assuming tab-delimited

g <- graph.adjacency(
  as.matrix(as.dist(cor(t(MyData), method="pearson"))),
  mode="undirected",
  weighted=TRUE,
  diag=FALSE
)
ADD REPLYlink modified 11 months ago • written 11 months ago by Kevin Blighe32k

Thank you, there is another "x" and "numeric" issue:

Error in cor(t(MyData), method = "pearson") : 'x' must be numeric
ADD REPLYlink written 11 months ago by Farbod3.2k

Try as.matrix(as.dist(cor(t(data.matrix(MyData)), method="pearson")))

ADD REPLYlink written 11 months ago by Kevin Blighe32k

Hi, it seems that it is a problem with huge matrix file so I did it simple and just put 100 lines in the matrix. I want to know by which command I can create the plot? is it just plot() ?(sorry for simple questions)


library(igraph)
MyData <- read.table('/home/emami/Desktop/A1.matrix', sep="\t") #assuming tab-delimited
g <- graph.adjacency(
  as.matrix(as.dist(cor(t(data.matrix(MyData)), method="pearson"))),
  mode="undirected",
  weighted=TRUE,
  diag=FALSE
)
plot (g)
ADD REPLYlink written 11 months ago by Farbod3.2k

Yes, it will be difficult to produce a network of a large data-matrix because it has to compute a squared distance/correlation matrix. For example, if you tried it on a transcriptome of 20,000 protein-coding genes, you would have to generate a distance matrix of 400,000,000 data points.

You can generate a quick plot with just the base R plot() function, which will interpret the graph object. plot.igraph should also work. However, between the graph adjacency object and actually plotting the graph, there are many other important steps (as you can see above in the tutorial)

ADD REPLYlink written 11 months ago by Kevin Blighe32k

What is the significance of the Modularity column in the final commSummary data frame? To my understanding, modularity is a singular value that speaks to the entire network - why is each node assigned its own value?

ADD REPLYlink written 10 weeks ago by hwastyk0

In this context, it relates to the community structure, not the entire graph. Also, based on the fact that I have used edge.betweenness.community() for the purpose of identifying community structure in this tutorial, the modularity score relates to the maximum score achieved for each node when identifying the community structures.

modularity

Logical constant, whether to calculate the maximum modularity score, considering all possibly community structures along the edge-betweenness based edge removals.

[source: http://igraph.org/r/doc/cluster_edge_betweenness.html]

Does that help? - hope so.

ADD REPLYlink written 10 weeks ago by Kevin Blighe32k

Thank you very much for the code!

I have two very basic questions. 1. Why do you use as input the four conditions in "estrogenMainEffects"? 2. Don´t you should use just one condition to find the "transcription modules" in that particular scenario?

Thank you again for your contribution! Regards, Luis

ADD REPLYlink written 16 days ago by luis.valenz.v0

Hey Luis! This is really just a simple tutorial to show one way of constructing a network / minimum spanning tree. It would indeed be interesting to construct the network separately for each of the 4 conditions, and to then compare the networks between these. There are many diverse ways to conduct a network analysis.

ADD REPLYlink written 16 days ago by Kevin Blighe32k

Very awesome code and tutorial! I've been thinking how can I investigate the network overlap and/or uniqueness? For example, for time-course study, that'll be very interesting if looks at network "hand-shake" between two continuous time point, e.g Day3 has own network and Day4 has its own network, in the same plot, but also shows some interactions (maybe gene expressed in both days, or the subnetwork btw two days because some genes have correlations). Do you have any idea of how to achieve that? Thanks.

ADD REPLYlink written 10 days ago by joseph.houjue0

Hey Joseph. Thank you! I have not included that type of functionality in this tutorial, and other network analysis tools neither have sufficiently tackled this issue.

My recommendation would be to compare genes by the following metrics:

  • Hub score (higher score = more influence)
  • Vertex degree (higher score = more influence)
  • Community members, i.e., other genes that appear in the same community as your gene of interest
  • 1st neighbours of your gene of interest (see http://igraph.org/r/doc/neighbors.html )

You can also directly compare 2 networks by the 'variance of information' (vi) metric (not relevant here). Identical graphs will have a vi=0

compare(g1, g2, method="vi")
ADD REPLYlink written 10 days ago by Kevin Blighe32k

get error info as: Error in i_compare(comm1, comm2, method) : (list) object cannot be coerced to type 'double'

I don't understand what's the problem.

ADD REPLYlink written 9 days ago by joseph.houjue0

Oh, my apologies. The compare() function is to compare community structures, like:

# create minimum spanning tree (MST) for graph1
mst1 <- mst(g1, algorithm="prim")
# identify communities in MST for graph1
comm1 <- edge.betweenness.community(mst1, directed=FALSE)

# repeat for graph2
mst2 <- mst(g2, algorithm="prim")
comm2 <- edge.betweenness.community(mst2, directed=FALSE)

# compare
compare(comm1, comm2, method="vi")

This just outputs a single number, though. If the community structures are identical, the value is 0.0.

ADD REPLYlink modified 9 days ago • written 9 days ago by Kevin Blighe32k

Thanks! That sounds only indicates either identical or discrepancy without any further details. I wonder, we can make to networks, g1 and g2, the genes A, B, and C appear in both networks. Can we let them "cross-talk" vis the genes A, B, and C in the Cytoscape? or how to make two networks connected? Any comment?

ADD REPLYlink written 9 days ago by joseph.houjue0

Cytoscape NetworkAnalyzer plugin allows you to do many extra things like that. I believe you can export your igraph objects to Cytoscape with toCytoscape(igraphobj), from cyREST package

ADD REPLYlink written 9 days ago by Kevin Blighe32k

Hi, I tried "Step 2 Create the graph and tree objects" with my own microarray data. But values such as edgeweights and vSizes are all NA, and therefore I cannot get a plot with the error message of "need finite 'xlim' values. My own data is 182 obs. of 661 variables. Is there anything that I should check to solve my problem? Thanks.

ADD REPLYlink modified 6 days ago • written 6 days ago by kumimesy0

Was the graph.adjacency() function successfully run?

ADD REPLYlink written 6 days ago by Kevin Blighe32k

Thank you Kevin, when I run graph.adjacency(), there was no error message. Although I viewed the list "g", it was difficult for me to know whether it was successful or not. Could you please let me know how to check the output of graph.adjacency()?

ADD REPLYlink written 6 days ago by kumimesy0

Hey, if you just type g at the console, it should display some textual information about the graph object.

Can you show the exact command that you used for graph.adjacency() ?

Your input data may also contain NAs somewhere. What is the source of your data?

ADD REPLYlink written 6 days ago by Kevin Blighe32k

Hi Kevin, the command for graph.adjacency and the output of typing "g" at the console is as below. I found that there are 196 NAs in my data. My data is normalized microarray data of blood from 661 human subjects. When there are NAs, do I need to add specific argument? I also found that when I entered " g <- simplify(g, remove.multiple=TRUE, remove.loops=TRUE)", there was an error message with "Error in simplify(g, remove.multiple = TRUE, remove.loops = TRUE) : unused arguments (remove.multiple = TRUE, remove.loops = TRUE)"

Thank you so much.

g <- graph.adjacency( as.matrix(as.dist(cor(t(datExpr_LG5), method="pearson"))), mode="undirected", weighted=TRUE, diag=FALSE )

g IGRAPH 6940ee1 UNW- 182 16471 -- + attr: name (v/c), weight (e/n) + edges from 6940ee1 (vertex names): [1] ID3--ANGPTL1 ID3--FAM129C ID3--SETBP1 ID3--AEBP1 ID3--CXXC5 ID3--CYB561A3 ID3--PLEKHA2 ID3--TIMELESS
[9] ID3--PMEPA1 ID3--CD200 ID3--CD79A ID3--ZCCHC18 ID3--FCRL5 ID3--ADAM28 ID3--ID3.1 ID3--ID3.2
[17] ID3--ADAM28.1 ID3--SWAP70 ID3--PKIG ID3--BCL11A ID3--CXXC5.1 ID3--TCF4 ID3--BCL11A.1 ID3--SIPA1L3
[25] ID3--FAIM3 ID3--BANK1 ID3--PIK3C2B ID3--ST6GAL1 ID3--POU2AF1 ID3--PKIG.1 ID3--TTN ID3--FCRL1
[33] ID3--PPAPDC1B ID3--PTPRK ID3--RIC3 ID3--VAV2 ID3--RRAS2 ID3--RNFT2 ID3--CNTNAP2 ID3--RIC3.1
[41] ID3--PTPRK.1 ID3--SWAP70.1 ID3--EBF1 ID3--DBNDD1 ID3--PPAPDC1B.1 ID3--BCL7A ID3--IGHV5.78 ID3--ZNF285
[49] ID3--MOB3B ID3--SIK1 ID3--TLR10 ID3--COBLL1 ID3--RIC3.2 ID3--PCDH9 ID3--FAM129C.1 ID3--LCN10
[57] ID3--E2F5 ID3--SNX22 ID3--RNFT2.1 ID3--STAP1 ID3--QRSL1 ID3--PMEPA1.1 ID3--RIC3.3 ID3--CR2
+ ... omitted several edges

ADD REPLYlink written 6 days ago by kumimesy0

If there are NAs in the data, then I am not sure how it manages to successfully produce the g object. The cor() function (with default settings) applied to data with missing values will throw an error. Perhaps it is producing a corrupt g object.

The key may be in the 'use' parameter, which is passed to cor().

You could try

g <- graph.adjacency( as.matrix(as.dist(cor(t(datExpr_LG5), use="pairwise.complete.obs", method="pearson"))), mode="undirected", weighted=TRUE, diag=FALSE )
ADD REPLYlink written 6 days ago by Kevin Blighe32k

Thanks! I tried the command as you suggested, but in the next step of "g <- simplify(g, remove.multiple=TRUE, remove.loops=TRUE)", I still get the error message with "Error in simplify(g, remove.multiple = TRUE, remove.loops = TRUE) : unused arguments (remove.multiple = TRUE, remove.loops = TRUE)". Could you please suggest any other method? I appreciate your help.

ADD REPLYlink written 6 days ago by kumimesy0

I have never seen that error for that function in the past. If you skip this step, are you able to produce the graph?

Other things to try:

  • what happens when you just type simplify ?
  • can you try g <- igraph::simplify(g, remove.multiple=TRUE, remove.loops=TRUE)
ADD REPLYlink written 5 days ago by Kevin Blighe32k

It works with your suggestion "g <- igraph::simplify(g, remove.multiple=TRUE, remove.loops=TRUE)". Thanks! Before you suggested the new graph.adjacency command, all values of both edgeweights and vSizes were NA. After I used your new graph.adjacency command, edgeweights are not NA. But all vSizes are still NA. I cannot produce the graph. Could you please suggest any other method in this situation?

ADD REPLYlink written 5 days ago by kumimesy0

Okay, that indicates that there is a namespace issue, i.e., there is some other package that is loaded in your R session that shares the same function names as those functions used by igraph package. You may consider saving your R session via save.image("MySession.rdata"), restarting R, loading just igraph package, and then loading your data with load("MySession.rdata") (and then trying the commands again).

ADD REPLYlink written 5 days ago by Kevin Blighe32k

Yes, the original "simplify" command works well when I load igraph only. However, vSizes are still NA. Maybe it is caused by NA in my data, as you suggested earlier. Could you let me know the method to deal with NA problem? Thanks!

ADD REPLYlink written 5 days ago by kumimesy0

For vSizes, you have to specify your original dataframe into the command. So, yours would be:

vSizes <- (scale01(apply(datExpr_LG5, 1, mean)) + 1.0) * 10

You can also just skip this part and specify your vertex sizes manually when calling the plot() function, eg:

vertex.size=3.0
ADD REPLYlink written 5 days ago by Kevin Blighe32k

Sure, I specified my original dataframe into the command. But it does not work. However, as you suggested, when I skipped that part and specified vertex sizes manually, it worked! Thank you so much. By the way, two thirds of my nodes don't have any edges. Could you let me know how to delete nodes without edges?

ADD REPLYlink written 5 days ago by kumimesy0

Great!

The nodes / vertices that have no edges are the ones whose original edge values fell below your chosen threshold for correlation. You can remove them using this function: http://igraph.org/r/doc/delete_vertices.html

ADD REPLYlink written 5 days ago by Kevin Blighe32k

OK, thank you very much for your kind help! I wish you success and happiness.

ADD REPLYlink written 5 days ago by kumimesy0

And you too, of course!

ADD REPLYlink written 4 days ago by Kevin Blighe32k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1828 users visited in the last hour