Re: [R] Understanding mod.matrix for directed networks

2015-07-13 Thread Gábor Csárdi
I am sorry for the slow response. Please note that these are better
channels for igraph help: http://igraph.org/r/#help

As for your question, can you please send some R code that
demonstrates your problem?

Gabor

On Tue, May 19, 2015 at 1:50 AM, Aziz, Muhammad Fayez
 wrote:
> Dear Gabor,
>
>
>
> Please find attached an Excel file with detailed information on a four node
> directed network to calculate its pairwise modularity matrix using igraph:
> mod.matrix(). I have tried multiple combinations to figure out how the
> formula works or is applied but failed to find consistency, specially for
> the pairs of arcs in opposing directions where the pairwise modularity is
> different (highlighted and color-coded). I gave membership(wtc) as input to
> mod.matrix() but not even sure if its used in the formula provided in the
> following R manual page:
>
>
>
> http://igraph.org/r/doc/modularity.html
>
>
>
> Advice with a solved example in the Excel sheet would be deeply appreciated.
>
>
>
> Thanks and regards,
>
> Fayez
>
> University of Illinois at Urbana Champaign, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] install.packages and dependencies=TRUE

2013-12-17 Thread Gábor Csárdi
> On Tue, Dec 17, 2013 at 11:36 AM, Duncan Murdoch
>  wrote:
[...]
>> I imagine some package has a function that does what you want, but I don't
>> know it.  It wouldn't be hard to put one together as follows:
>>
>> 1.  install your package without its dependencies.

This does not seem to work if the package had 'Depends' or 'Imports'
as well. What is the correct way to install a local package, so that
its dependencies are pulled from CRAN?

>> 2.  use tools::package_dependencies() to find the (non-recursive)
>> dependencies.

This does not seem to work, because the dependencies are only checked on CRAN.

>> 3.  install those, with their dependencies.

In summary, it is not quite trivial to do this correctly, if you look
at devtools:::install_deps and and devtools:::parse_deps, it is not 10
lines of code.

Anyway, I can just take the code from devtools or use their unreleased version.

Thanks again,
Gabor

[...]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] install.packages and dependencies=TRUE

2013-12-17 Thread Gábor Csárdi
Thanks!

Btw, install() from the devtools package can do this in theory, but
not in practice, because of a bug (it silently ignores "Suggests").
This is fixed in their github version.

Just to add something useful here.

Gabor

On Tue, Dec 17, 2013 at 11:36 AM, Duncan Murdoch
 wrote:
> On 17/12/2013 11:26 AM, Gábor Csárdi wrote:
>>
>> Dear all,
>>
>> I am trying to install a private package, with its dependencies. However,
>> both
>>
>> install.packages("sand_1.0.tar.gz", dependencies=TRUE, repos=NULL,
>> type="source")
>>
>> and
>>
>> install.packages("sand_1.0.tar.gz", dependencies="Suggests",
>> repos=NULL, type="source")
>>
>> fail to install suggested packages:
>>
>> > packageDescription("sand")$Suggests
>> [1] "network, sna, ape, ergm, mixer, vioplot, ROCR, fdrtool, huge"
>>
>> Based on the docs, I got the (obviously wrong) impression, that it was
>> possible to install suggested packages. From ?install.packages,
>> dependencies argument:
>>
>>‘TRUE’ means to use ‘c("Depends", "Imports", "LinkingTo",
>>"Suggests")’ for ‘pkgs’ and ‘c("Depends", "Imports",
>>"LinkingTo")’ for added dependencies: this installs all the
>>packages needed to run ‘pkgs’, their examples, tests and
>>vignettes (if the package author specified them correctly).
>>
>> > library(ergm)
>> Error in library(ergm) : there is no package called ‘ergm’
>> > library(huge)
>> Error in library(huge) : there is no package called ‘huge’
>>
>> What am I doing wrong, and more importantly, what is the correct way
>> to install _all_ dependencies of a package?
>
>
> The problem is with repos=NULL (i.e. a local install).  Since none of those
> dependencies are local, they aren't found and won't be installed.
>
> I imagine some package has a function that does what you want, but I don't
> know it.  It wouldn't be hard to put one together as follows:
>
> 1.  install your package without its dependencies.
> 2.  use tools::package_dependencies() to find the (non-recursive)
> dependencies.
> 3.  install those, with their dependencies.
>
> You could add a step to filter the list in 2 so that you don't re-install
> something that is already there.
>
> Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] install.packages and dependencies=TRUE

2013-12-17 Thread Gábor Csárdi
Answer to myself. 'dependencies' are

Not used if ‘repos = NULL’.

Sorry for the noise.

Gabor

On Tue, Dec 17, 2013 at 11:26 AM, Gábor Csárdi  wrote:
> Dear all,
>
> I am trying to install a private package, with its dependencies. However, both
>
> install.packages("sand_1.0.tar.gz", dependencies=TRUE, repos=NULL,
> type="source")
>
> and
>
> install.packages("sand_1.0.tar.gz", dependencies="Suggests",
> repos=NULL, type="source")
>
> fail to install suggested packages:
>
>> packageDescription("sand")$Suggests
> [1] "network, sna, ape, ergm, mixer, vioplot, ROCR, fdrtool, huge"
>
> Based on the docs, I got the (obviously wrong) impression, that it was
> possible to install suggested packages. From ?install.packages,
> dependencies argument:
>
>   ‘TRUE’ means to use ‘c("Depends", "Imports", "LinkingTo",
>   "Suggests")’ for ‘pkgs’ and ‘c("Depends", "Imports",
>   "LinkingTo")’ for added dependencies: this installs all the
>   packages needed to run ‘pkgs’, their examples, tests and
>   vignettes (if the package author specified them correctly).
>
>> library(ergm)
> Error in library(ergm) : there is no package called ‘ergm’
>> library(huge)
> Error in library(huge) : there is no package called ‘huge’
>
> What am I doing wrong, and more importantly, what is the correct way
> to install _all_ dependencies of a package?
>
> Thanks, Best,
> Gabor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] install.packages and dependencies=TRUE

2013-12-17 Thread Gábor Csárdi
Dear all,

I am trying to install a private package, with its dependencies. However, both

install.packages("sand_1.0.tar.gz", dependencies=TRUE, repos=NULL,
type="source")

and

install.packages("sand_1.0.tar.gz", dependencies="Suggests",
repos=NULL, type="source")

fail to install suggested packages:

> packageDescription("sand")$Suggests
[1] "network, sna, ape, ergm, mixer, vioplot, ROCR, fdrtool, huge"

Based on the docs, I got the (obviously wrong) impression, that it was
possible to install suggested packages. From ?install.packages,
dependencies argument:

  ‘TRUE’ means to use ‘c("Depends", "Imports", "LinkingTo",
  "Suggests")’ for ‘pkgs’ and ‘c("Depends", "Imports",
  "LinkingTo")’ for added dependencies: this installs all the
  packages needed to run ‘pkgs’, their examples, tests and
  vignettes (if the package author specified them correctly).

> library(ergm)
Error in library(ergm) : there is no package called ‘ergm’
> library(huge)
Error in library(huge) : there is no package called ‘huge’

What am I doing wrong, and more importantly, what is the correct way
to install _all_ dependencies of a package?

Thanks, Best,
Gabor

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] CRAN RSS feeds about updates and package checks

2013-05-07 Thread Gábor Csárdi
Dear All,

I have put together a simple web service that notifies you about new and
updated R packages and/or if CRAN package checks fail for your packages. It
is all done via RSS feeds and there is a short description at
http://cranky.igraph.org

The feeds are dynamically created, so you don't have to subscribe for
updates and checks about all packages, but you can follow a single package,
packages by a given author or maintainer, the (reverse) dependencies of a
package, etc. You can even get a feed with packages whose description
contains a keyword. Here are some simple examples:

All packages:
http://cranky.igraph.org/feed/news

Packages that depend on the ggplot2 package:
http://cranky.igraph.org/feed/news/uses/ggplot2

Packages 'ggplot2' depends on:
http://cranky.igraph.org/feed/news/usedby/ggplot2

Packages by a single person:
http://cranky.igraph.org/feed/news/author/youknowitall

Packages that contain 'network' in the description field:
http://cranky.igraph.org/feed/news/description/network

All package checks:
http://cranky.igraph.org/feed/checks

All packages checks for ggplot2 dependencies:
http://cranky.igraph.org/feed/checks/usedby/ggplot2

I have created this for my own needs, and have been using it for a couple
of weeks now. I thought it might be useful for others as well. It could be
a lot more flexible, e.g. a complex search feature would be great, but I
think it is already useful as it is.

Note that this is independent of CRAN and the R website, so please don't
bother R-core or CRAN maintainers about possible bugs or questions. Contant
me directly instead or report a bug on github, see http://cranky.igraph.org.

Best,
Gabor

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] possible bug with largest.cliques in igraph_0.6-3

2012-10-31 Thread Gábor Csárdi
Indeed this seems to be a bug, if the graph is directed. The
workaround is to convert it to an undirected graph, the clique
computation ignores direction anyway:

library(igraph)
adj <- matrix(1, nrow=11, ncol=11) - diag(11)
g <- graph.adjacency(adj)
largest.cliques(g)
# [[1]]
#  [1] 10  8  1
#
# [[2]]
#  [1] 9 7 1
#
# [[3]]
#  [1] 8 7 1

largest.cliques(as.undirected(g))
# [[1]]
#  [1]  1  2  3  4  5  6  7  8  9 10 11

Btw. please do not send igraph bug reports to r-help, either send them
to igraph-help (see http://igraph.sf.net), to me directly, or, the
best for us, report the bug at https://bugs.launchpad.net/igraph.
Thanks.

I have reported a bug for this, you can follow it here, in case you
are interested:
https://bugs.launchpad.net/igraph/+bug/1073800

On Wed, Oct 31, 2012 at 11:15 PM, Christos Hatzis
 wrote:
> There is a problem with the largest clique computation in the recent version
> of igraph.
[...]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help finding edge connecting two nodes

2012-10-19 Thread Gábor Csárdi
On Fri, Oct 19, 2012 at 2:50 PM, Dhaval Adjodah  wrote:
[...]
> Your way works best! Another way I found from stackoverflow (see the post
> at
> http://stackoverflow.com/questions/12964332/igraph-edge-between-two-vertices/12980550#12980550)
> was
> to convert the graph into an adjacency matrix and then use simple matrix
> indices .

Just make this clear. The example (repeated below) on the
stackoverflow page does _not_ convert the graph into an adjacency
matrix. The indexing only makes the graph look as if it was an
adjacency matrix. But there is no conversion at all.

Gabor

ps. I would appreciate if you didn't cross-post your questions
everywhere (R-help, igraph-help and stackoverflow, maybe other places
as well). Please only post it on the platform you prefer first and
then, if you don't get a good answer, try elsewhere. Thanks!

library(igraph)
g <- graph.ring(10)
g[1,2]
# [1] 1
E(g)$weight <- runif(ecount(g))
g[1,2]
# [1] 0.8115639

[...]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help

2012-08-22 Thread Gábor Csárdi
Hi,

the thing is, you didn't really have any questions in your email. What
is the problem with your code? Is it not giving the expected results?
More below.

On Wed, Aug 22, 2012 at 8:31 AM, Yanis El Omari
 wrote:
[...]
> Rm(list())

What is this this supposed to do? Do you mean 'rm(list=ls())' ?

> library(R.matlab)
> library(igraph)
> path<-("D:/adj_matrices/nonweighted_GOVSOV")
> setwd(path)
> vector.files<-paste("nonweighted_GOVSOV",1:265, ".mat",sep="")
> dat<-list()
>
> for(i in 1:265) {
> dat[[i]] <-readMat(file.path(path,vector.files[i]))
> adj<-do.call(rbind, dat[[i]])
> g<-graph.adjacency(adj, mode=c("directed"), weighted=T) # the graph object of 
> the network
>
> a<-length(V(g)) #the number of nodes
>
> indeg<-rep(0,a) #the vector where I 
> want to write the degree of each node for week i

The above two lines are not needed, you can remove them.

> indeg<-degree(g)  
>#degree calculation for 
> each node of the network
>
> write(indeg, "indeg[i]".txt, sep="\n")

This is probably wrong, the results are written to a file named
"indeg[i].txt", I think you want something like

write(indeg, sprintf("indeg[%i].txt", i), sep="\n")

> }
>
>
> Is there some obvious mistake in my program, or does anyone have a solution 
> to do this?

Maybe, but what is your problem with it? (Apart from the incorrect
naming of the output files.)

Gabor

[...]

-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph: Turn multiple edges into weights

2012-08-15 Thread Gábor Csárdi
On Tue, Aug 14, 2012 at 5:09 PM, Jonas Michaelis
 wrote:
> Dear all,
>
>
> I have some network data - about 300 vertices and several thousand edges. I
> am looking for a way to turn multiple edges into weights of the edges. I
> looked around and - surprisingly? - haven't found anything. Is there an
> easy way to do this?

simplify() by default sums the edge weights, so just set all weights
to 1, and call simplify().

E.g.

## A graph with multiple edges
g <- graph.formula(A:A:A -- B:C:D, A -- B, simplify=FALSE)
str(g)
E(g)$weight <- 1
g2 <- simplify(g, remove.loops=FALSE)
str(g2, e=TRUE)

Best,
Gabor

>
> Best, Jonas
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [igraph] per-vertex statistics of edge weights

2012-08-15 Thread Gábor Csárdi
On Wed, Aug 15, 2012 at 4:10 PM, Sam Steingold  wrote:
[...]
> Also, this takes forever and consumes almost all 8GB RAM.
> It has been running on
>
> --8<---cut here---start->8---
> IGRAPH DNW- 18590 6734992 --
> + attr: name (v/c), count (v/n), weight (e/n)
> --8<---cut here---end--->8---
>
> for an hour and a half now.
[...]

g <- erdos.renyi.game(18590, 6734992, type="gnm")
E(g)$weight <- runif(ecount(g))

and then

al <- get.adjedgelist(g)
w <- E(g)$weight
tmp <- sapply(al, function(e) mean(w[e]))

is fairly quick:

> system.time(tmp <- sapply(al, function(e) mean(w[e])))
   user  system elapsed
  1.353   0.069   1.458

Gabor

-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] per-vertex statistics of edge weights

2012-08-15 Thread Gábor Csárdi
On Wed, Aug 15, 2012 at 2:04 PM, Sam Steingold  wrote:
> I have a graph with edge and vertex weights, stored in two data frames:
>
> --8<---cut here---start->8---
> vertices <- data.frame(vertex=c("a","b","c","d"),weight=c(1,2,1,3))
> edges <- data.frame(src=c("a","a","b","c","d"),dst=c("b","c","d","d","a"),
>   weight=c(1,2,1,3,1))
> --8<---cut here---end--->8---
>
> I can create a graph from this data:
>
> --8<---cut here---start->8---
> library(igraph)
> graph <- graph.data.frame(edges, vertices = vertices, directed=FALSE)
> --8<---cut here---end--->8---
>
> what I want is to compute some edge weight stats (mean/median/max/min/)
> for each vertex.
>
> I guess I can do something like
>
> --8<---cut here---start->8---
>> sapply(vertices$vertex, function (v) mean(E(g)[inc(v)]$weight))
> Note: no visible global function definition for 'inc'
> [1] 1.33 1.00 2.50 1.67
> --8<---cut here---end--->8---

For me this gives

Error in mean(E(g)[inc(v)]$weight) :
  error in evaluating the argument 'x' in selecting a method for
function 'mean': Error in match(x, table, nomatch = 0L) : object 'g'
not found

which is no wonder, since 'g' is not defined.

> but I was wondering if this is TRT, given the correct answer with a
> scary note.

I am not sure what TRT is, but I would do this as

sapply(V(graph), function(v) mean(E(graph)$weight[incident(graph, v)]))

Your solution is somewhat messy, because vertices$vertex is actually a
factor, etc.

Gabor

[...]

-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subgraph isomorphism using vertex labels

2012-08-01 Thread Gábor Csárdi
I am sorry, but I don't know what exactly is the problem. What's wrong
with this:

library(igraph)
kar <- nexus.get("karate")
star3 <- graph.formula(A -- B:C:D)
subiso <- graph.get.subisomorphisms.vf2(kar, star3)

Then you can query the symbolic ids:

V(kar)$name[ subiso[[1]]+1 ]   # This is actually a bug and the +1
should not be needed

Or for all isomorphic subgraphs:

subiso2 <- lapply(subiso, function(x) V(kar)$name[x+1])

Gabor

On Wed, Aug 1, 2012 at 11:27 PM, HIMANSHU MITTAL  wrote:
> Thanks,
> but the problem is that igraph doesn't even give the correct id mappings. it
> only gives the mapping of the structure(without labels)
>
> For above eg:
> igraph only sees the one edge structure(of graph 2) without labels or names
> and gives all possible edges in the main graph(1) to be isomorphic to the
> query graph(2)
>
>
> On Wed, Aug 1, 2012 at 9:20 PM, Gábor Csárdi  wrote:
>>
>> Hi,
>>
>> igraph will give you the mappings via vertex ids. If you want to use
>> symbolic vertex names, then attach a vertex attribute called 'name'.
>> Then any vector of numeric vertex ids (v, from graph g) can be
>> converted to vertex names via
>>
>> V(g)$name[v]
>>
>> or the more readable equivalent
>>
>> get.vertex.attribute(g, "name", v)
>>
>> Best,
>> Gabor
>>
>> On Tue, Jul 31, 2012 at 3:12 PM, HIMANSHU MITTAL  wrote:
>> > Hi all,
>> > I want to find all the mappings of one graph in another graph, based on
>> > their vertex labels
>> > Is there any way to do this in igraph based on vertex labels.
>> > (as far as i know Igraph allows the subgraph isomorphism based only on
>> > vertex and edge colors)
>> >
>> > Eg:
>> > graph 1:
>> > x(1) x(2)
>> > x(2) y(3)
>> > y(4) x(1)
>> > z(5) x(2)
>> >
>> > graph 2:
>> > x(1) y(2)
>> >
>> > # the brackets contain the corresponding vertex ids
>> >
>> > i would like my output to contain the two mappings from graph 1
>> > i.e
>> > x(2) y(3) &
>> > x(1) y(4)
>> >
>> > Regards,
>> > Himanshu Mittal
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Gabor Csardi  MTA KFKI RMKI
>
>



-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subgraph isomorphism using vertex labels

2012-08-01 Thread Gábor Csárdi
Hi,

igraph will give you the mappings via vertex ids. If you want to use
symbolic vertex names, then attach a vertex attribute called 'name'.
Then any vector of numeric vertex ids (v, from graph g) can be
converted to vertex names via

V(g)$name[v]

or the more readable equivalent

get.vertex.attribute(g, "name", v)

Best,
Gabor

On Tue, Jul 31, 2012 at 3:12 PM, HIMANSHU MITTAL  wrote:
> Hi all,
> I want to find all the mappings of one graph in another graph, based on
> their vertex labels
> Is there any way to do this in igraph based on vertex labels.
> (as far as i know Igraph allows the subgraph isomorphism based only on
> vertex and edge colors)
>
> Eg:
> graph 1:
> x(1) x(2)
> x(2) y(3)
> y(4) x(1)
> z(5) x(2)
>
> graph 2:
> x(1) y(2)
>
> # the brackets contain the corresponding vertex ids
>
> i would like my output to contain the two mappings from graph 1
> i.e
> x(2) y(3) &
> x(1) y(4)
>
> Regards,
> Himanshu Mittal
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph function "graph.bfs" unavailable

2012-07-12 Thread Gábor Csárdi
Hi David,

please make sure that you have the 0.6 version of igraph installed.
You might need to upgrade your R installation to install the 0.6
version of igraph.

Best,
Gabor

On Wed, Jul 11, 2012 at 10:36 AM, David Marx  wrote:
> Hi,
>
> I've installed the igraph package and have been otherwise using it 
> successfully, but when I try to use graph.bfs I get the error:
>
> could not find function "graph.bfs"
>
> Moreover, I don't seem to have the documentation installed either. (per 
> ?graph.bfs and ??graph.bfs).
>
> I'm using RStudio v0.95.262 on windows 7. Below is the info for my R build:
>
> R version 2.14.0 (2011-10-31)
> Copyright (C) 2011 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> If for some reason this algorithm really is just unavailable, maybe someone 
> can come up with another way to solve my problem. I need a function that 
> builds subgraphs up to a limited distance from an input root node. I feel 
> like this is a common enough task that there's probably an easier way to do 
> it, but I'm still learning what tools are available to me in igraph and built 
> my own solution. The code below was tested on a machine that didn't have 
> issues with graph.bfs (I changed some variable names for the purpose of this 
> post, so maybe I broke something):
>
>   isolated.subgraph <- function(main.graph, node.name, bfs.dist=2){
>   # Get vertex id for root node from input graph
>   node.vid <- V(main.graph)[nodeName==node.name][[1]]
>
>   # Traverse graph using breadth-first search
>   # to distance of 2 from root
>   node.bfs <- graph.bfs(main.graph, root=node.vid
>   ,callback=function(graph, 
> data, extra){data['dist'] == bfs.dist}
>   )
>
>   # Isolate pertinent subgraph from nodes in node.bfs.
>   # Need to trim out NaN vertices from node.bfs
>   node.g <- induced.subgraph(all, 
> node.bfs$order[which(!is.na(node.bfs$order))])
>   return(node.g)
>   }
>
> Thanks,
>
> David Marx
>
> Please note our office has moved:
>
> David Marx | Data Analyst Specialist, Claims Dept | SoundExchange, Inc.
> 733 10th Street, NW | 10th Floor | Washington, DC  20001
> P: 202.640.5858 | F: 202.640.5859 | i...@soundexchange.com
> www.SoundExchange.com | Facebook | Twitter| YouTube
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi  MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] [R-pkgs] igraph 0.6 released

2012-06-18 Thread Gábor Csárdi
Dear All,

we have released version 0.6 of the igraph package today. This is a
major new version, with a lot of new features, and (sadly) it is not
completely compatible with code that was written for the previous
igraph versions. (See "Major new features" below for details.)

I have included below a list of (bigger) changes. Please see the
details in the release notes and the NEWS section at the igraph
homepage: http://igraph.sf.net

Best Regards,
Gabor


=
Major new features
=

- Vertices and edges are numbered from 1 instead of 0.
  Note that this makes most of the old R igraph code incompatible
  with igraph 0.6. If you want to use your old code, please use
  the igraph0 package. See more at http://igraph.sf.net/relnotes-0.6.html.
- The '[' and '[[' operators can now be used on igraph graphs,
  for '[' the graph behaves as an adjacency matrix, for '[[' is
  is treated as an adjacency list. It is also much simpler to
  manipulate the graph structure, i.e. add/remove edges and vertices,
  with some new operators. See more at ?graph.structure.
- In all functions that take a vector or list of vertices or edges,
  vertex/edge names can be given instead of the numeric ids.
- New package 'igraphdata', contains a number of data sets that can
  be used directly in igraph.
- Igraph now supports loading graphs from the Nexus online data
  repository, see nexus.get(), nexus.info(), nexus.list() and
  nexus.search().
- All the community structure finding algorithm return a 'communities'
  object now, which has a bunch of useful operations, see
  ?communities for details.
- Vertex and edge attributes are handled much better now. They
  are kept whenever possible, and can be combined via a flexible API.
  See ?attribute.combination.
- R now prints igraph graphs to the screen in a more structured and
  informative way. The output of summary() was also updated
  accordingly.

=
R: Other new features
=

- It is possible to mark vertex groups on plots, via
  shading. Communities and cohesive blocks are plotted using this by
  default.
- Some igraph demos are now available, see a list via
  'demo(package="igraph")'.
- igraph now tries to select the optimal layout algorithm, when
  plotting a graph.
- Added a simple console, using Tcl/Tk. It contains a text area
  for status messages and also a status bar. See igraph.console().
- Reimplemented igraph options support, see igraph.options() and
  getIgraphOpt().
- Igraph functions can now print status messages.

===
R: New or updated functions
===

Community detection
---
- The multi-level modularity optimization community structure detection
  algorithm by Blondel et al. was added, see multilevel.community().
- Distance between two community structures: compare.communities().
- Community structure via exact modularity optimization,
  optimal.community().
- Hierarchical random graphs and community finding, porting the code
  from Aaron Clauset. See hrg.game(), hrg.fit(), etc.
- Added the InfoMAP community finding method, thanks to Emmanuel
  Navarro for the code. See infomap.community().

Shortest paths
--
- Eccentricity (eccentricity()), and radius (radius()) calculations.
- Shortest path calculations with get.shortest.paths() can now
  return the edges along the shortest paths.
- get.all.shortest.paths() now supports edge weights.

Centrality
--
- Centralization scores for degree, closeness, betweenness and
  eigenvector centrality. See centralization.scores().
- Personalized Page-Rank scores, see page.rank().
- Subgraph centrality, subgraph.centrality().
- Authority (authority.score()) and hub (hub.score()) scores support
  edge weights now.
- Support edge weights in betweenness and closeness calculations.
- bonpow(), Bonacich's power centrality and alpha.centrality(),
  Alpha centrality calculations now use sparse matrices by default.
- Eigenvector centrality calculation, evcent() now works for
  directed graphs.
- Betweenness calculation can now use arbitrarily large integers,
  this is required for some lattice-like graphs to avoid overflow.

Input/output and file formats
-
- Support the DL file format in graph.read(). See
  http://www.analytictech.com/networks/dataentry.htm.
- Support writing the LEDA file format in write.graph().

Plotting and layouts

- Star layout: layout.star().
- Layout based on multidimensional scaling, layout.mds().
- New layouts layout.grid() and layout.grid.3d().
- Sugiyama layout algorithm for layered directed acyclic graphs,
  layout.sugiyama().

Graph generators

- New graph generators: static.fitness.game(), static.power.law.game().
- barabasi.game() was rewritten and it supports three algorithms now,
  the default algorithm does not generate multiple or loop edges.
  The graph generation process can now start from 

Re: [R] the largest independent (stable) set on graphs

2012-06-12 Thread Gábor Csárdi
The unreleased 0.6 version of igraph has a much faster implementation
for this, you can download a nightly build source R package from here:
https://code.google.com/p/igraph/downloads/list

Make sure that you download the right file, there are C, Python
packages there as well. I can send you a windows binary package, if
you are using windows.

Note that in this version vertices and edges are numbered from one and
not from zero, so you might need to update your code.

Best Regards,
Gabor

On Tue, Jun 12, 2012 at 11:58 AM, Diogo Alagador  wrote:
> I am using the igraph package and I would like to obtain only 1 largest
> independent set from a sparse graph with aprox. 600 vertices. When I used
> the largest.independent.vertex.sets command I cannot obtain all the sets in
> a decent time, even if I need only 1. Any ideas on how to solve this?
>
> Thanks in advance,
> Diogo Alagador
> Biodiversity Chair, Univ Évora, Portugal
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] community finding in a graph and heatplot

2012-06-04 Thread Gábor Csárdi
On Sun, Jun 3, 2012 at 4:11 PM, Aziz, Muhammad Fayez  wrote:
>
> Hmm interesting. To come to think of it there could be many disconnected 
> components in the graph and thus there should be a generic way to either 
> mitigate the disconnectedness in the dendrogram or in the original graph. I 
> had no luck in finding such a trick though google search. I then ran the 
> script on minute-scale graphs and have following results:
>
> 1) disconnected graph with three modules:
>
> *Vertices 9
> *Edges
> 1 2 1
> 2 3 1
> 3 1 1
> 4 5 1
> 5 6 1
> 6 4 1
> 7 8 1
> 8 9 1
> 9 7 1
>
> corresponding fgc$merges matrix:
>
>     [,1] [,2]
> [1,]    1    0
> [2,]    2    9
> [3,]    7    6
> [4,]    8   11
> [5,]    4    3
> [6,]    5   13
>
> 2) connected graph by adding links 1-2 and 4-7 in graph 1):
>
> *Vertices 9
> *Edges
> 1 2 1
> 2 3 1
> 3 1 1
> 4 5 1
> 5 6 1
> 6 4 1
> 7 8 1
> 8 9 1
> 9 7 1
> 1 4 1
> 4 7 1
>
> corresponding fgc$merges matrix:
>
>     [,1] [,2]
> [1,]    2    1
> [2,]    0    9
> [3,]    8    7
> [4,]    6   11
> [5,]    5    4
> [6,]    3   13
> [7,]   14   12
> [8,]   15   10
>
> There needs to be a generic way to get fgc$merges of the form 2) from 1). 
> Hints please.

Well, how do you merge the unconnected components? I guess you could
come up with an order based on modularity, or just merge them in
arbitrary order. The following is from igraph 0.6, and I haven't tried
it on your data, but it might just work. It merges the individual
subtrees in arbitrary order.

complete.dend <- function(comm) {
  merges <- comm$merges
  if (nrow(merges) < comm$vcount-1) {
miss <- seq_len(comm$vcount + nrow(merges))[-as.vector(merges)]
miss <- c(miss, seq_len(length(miss)-2) + comm$vcount+nrow(merges))
miss <- matrix(miss, byrow=TRUE, ncol=2)
merges <- rbind(merges, miss)
  }
  storage.mode(merges) <- "integer"

  merges
}

Best,
Gabor

[...]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph and igraph0

2012-06-04 Thread Gábor Csárdi
On Sat, Jun 2, 2012 at 9:58 AM, jalantho...@verizon.net
 wrote:
> Could someone tell me the difference between igraph and igraph0?
>
> I searched the CRAN web site, but cannot find an explantion of the 
> differences.

You are right that this should be in the package description.

There is no difference currently. igraph will have an update soon that
will make it incompatible with current packages and code, igraph0 will
serve as a backward compatible snapshot. All future development will
go to 'igraph'.

Gabor

> Thanks, Alan
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and igraph problems

2012-06-04 Thread Gábor Csárdi
On Sun, Jun 3, 2012 at 3:43 AM, peter dalgaard  wrote:
>
> On Jun 2, 2012, at 15:43 , jalantho...@verizon.net wrote:
>
>> Why is igraph 0.5.5 not on the igraph sourceforgwe home page?
>
> You'll have to ask the igraph developers... Possibly, they just ran out of 
> "round tuits".

Yes, kind of. :)

Also, there is no real difference between 0.5.4 and 0.5.5, only some
R-specific changes, to make the package on different platforms, to
make 'R CMD check' clean, etc.

G.

> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] community finding in a graph and heatplot

2012-06-03 Thread Gábor Csárdi
The problem is that your graph is unconnected, it has two components
and the as.dendrogram() function in igraph cannot handle that.
fastgreedy.community() returns a matrix of merges that is not a
complete dendrogram, the final top level merge of the components is
missing.

A workaround is to modify the result of fastgreedy.community and add
the missing row to the merges matrix, before calling as.dendrogram().

G.

On Thu, May 31, 2012 at 7:42 PM, Aziz, Muhammad Fayez
 wrote:
>
> Thank you so much Gabor for taking this on. Please find attached a sample 
> scenario with the problem of malfunctioning dendogram by fgc. I hope this 
> helps you narrow down to the solution.
>
> Best,
> Fayez
>
> 
> From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor 
> Csárdi [csa...@rmki.kfki.hu]
> Sent: Thursday, May 31, 2012 4:23 PM
> To: Aziz, Muhammad Fayez
> Cc: r-help@r-project.org
> Subject: Re: [R] community finding in a graph and heatplot
>
> On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez
>  wrote:
>>
>> Thank you so much Gabor for your reply. I had spotted your post earlier and 
>> it worked like a charm. Interestingly I have just ran into a trouble with 
>> the stament dend <- igraph:::as.dendrogram.igraph.walktrap(fc). Apparently 
>> the members are empty as when I print(dend) it says 'dendrogram' with 2 
>> branches and  members total, at height 93" while the error with using dend 
>> with dendrapply remians to be
>>
>> Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL
>>
>> Any ideas?
>
> I would need to see fgc for this. Can you send it to me in private? Or
> send some self-contained example that generates the same error?
>
> Gabor
>
>> My code looks like this
>>
>>                File2Open = paste(FilePath, "NetworkFiles\\net\\", NetPrefix, 
>> " ", TPPostfix, ".net", sep = "")
>>                g <- read.graph(File2Open, format="pajek")
>>
>>                g <- delete.isolates(g)
>>                g <- simplify(g)
>>
>>                fgc <- fastgreedy.community(g, modularity=TRUE, weights = 
>> E(g)$weight)
>>                ModularityIndexfgc <- max(fgc$modularity) # fgc modularity
>>                ModularityIndexng <- modularity(g, membership, weights = 
>> E(g)$weight) # newman-girvan modularity
>>                dend <- igraph:::as.dendrogram.igraph.walktrap(fgc)
>>
>>                png(filename = paste(FilePath, 
>> "Analysis\\Graphs\\EColiStressModuleHeatMap", NetPrefixAbbr, TPPostfix, 
>> ".png", sep = ""), width = 800, height = 800) # heat map is square
>>
>>                adjMatrix = get.adjacency(g, attr="weight")
>>                DendNodeCounter <- 0 # counter for ColorGroupsOrdered
>>                ColorGroupsOrdered <- rep("red", vcount(g))
>>                dendrapply(dend, colLab) # modifies ColorGroupsOrdered
>> 
>> From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor 
>> Csárdi [csa...@rmki.kfki.hu]
>> Sent: Thursday, May 31, 2012 10:45 AM
>> To: Aziz, Muhammad Fayez
>> Cc: r-help@r-project.org
>> Subject: Re: [R] community finding in a graph and heatplot
>>
>> On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez
>>  wrote:
>>>
>>> Hi everyone,
>>>
>>> I am using the fastgreedy.community function to get the $merges matrix and 
>>> the $modularity vector. This serves my purpose of testing modularity of my 
>>> graph. But I am "greedy" to plot the heat map and dendrrogram based on the 
>>> $merges dendogram matrix. I know that heatplot does the graphics part but I 
>>> am not sure if the dendogram generated by the heatplot will match the one 
>>> given by fastgreedy.community in all cases and that the heat map will 
>>> represent the same clustering.
>>
>> No, they are different. To plot fast-greedy results as a dendrogram,
>> see this and the follow-ups:
>> http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html
>>
>> Gabor
>>
>>> Tell me if my apprehension is incorrect. Otherwise please let me know of 
>>> any alternatives. Here is the code I am testing so far:
>>>
>>> # http://igraph.sourceforge.net/doc/R/modularity.html
>>> # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html
>>> # http://igraph.sourceforge.net/doc/R/graph.constructors.html
>

Re: [R] community finding in a graph and heatplot

2012-05-31 Thread Gábor Csárdi
On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez
 wrote:
>
> Thank you so much Gabor for your reply. I had spotted your post earlier and 
> it worked like a charm. Interestingly I have just ran into a trouble with the 
> stament dend <- igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the 
> members are empty as when I print(dend) it says 'dendrogram' with 2 branches 
> and  members total, at height 93" while the error with using dend with 
> dendrapply remians to be
>
> Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL
>
> Any ideas?

I would need to see fgc for this. Can you send it to me in private? Or
send some self-contained example that generates the same error?

Gabor

> My code looks like this
>
>                File2Open = paste(FilePath, "NetworkFiles\\net\\", NetPrefix, 
> " ", TPPostfix, ".net", sep = "")
>                g <- read.graph(File2Open, format="pajek")
>
>                g <- delete.isolates(g)
>                g <- simplify(g)
>
>                fgc <- fastgreedy.community(g, modularity=TRUE, weights = 
> E(g)$weight)
>                ModularityIndexfgc <- max(fgc$modularity) # fgc modularity
>                ModularityIndexng <- modularity(g, membership, weights = 
> E(g)$weight) # newman-girvan modularity
>                dend <- igraph:::as.dendrogram.igraph.walktrap(fgc)
>
>                png(filename = paste(FilePath, 
> "Analysis\\Graphs\\EColiStressModuleHeatMap", NetPrefixAbbr, TPPostfix, 
> ".png", sep = ""), width = 800, height = 800) # heat map is square
>
>                adjMatrix = get.adjacency(g, attr="weight")
>                DendNodeCounter <- 0 # counter for ColorGroupsOrdered
>                ColorGroupsOrdered <- rep("red", vcount(g))
>                dendrapply(dend, colLab) # modifies ColorGroupsOrdered
> 
> From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor 
> Csárdi [csa...@rmki.kfki.hu]
> Sent: Thursday, May 31, 2012 10:45 AM
> To: Aziz, Muhammad Fayez
> Cc: r-help@r-project.org
> Subject: Re: [R] community finding in a graph and heatplot
>
> On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez
>  wrote:
>>
>> Hi everyone,
>>
>> I am using the fastgreedy.community function to get the $merges matrix and 
>> the $modularity vector. This serves my purpose of testing modularity of my 
>> graph. But I am "greedy" to plot the heat map and dendrrogram based on the 
>> $merges dendogram matrix. I know that heatplot does the graphics part but I 
>> am not sure if the dendogram generated by the heatplot will match the one 
>> given by fastgreedy.community in all cases and that the heat map will 
>> represent the same clustering.
>
> No, they are different. To plot fast-greedy results as a dendrogram,
> see this and the follow-ups:
> http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html
>
> Gabor
>
>> Tell me if my apprehension is incorrect. Otherwise please let me know of any 
>> alternatives. Here is the code I am testing so far:
>>
>> # http://igraph.sourceforge.net/doc/R/modularity.html
>> # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html
>> # http://igraph.sourceforge.net/doc/R/graph.constructors.html
>>
>> library(igraph)
>> library(made4)
>>
>> g <- graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE)
>> print(g)
>> ModuleInfo <- fastgreedy.community(g)
>> print(ModuleInfo)
>> heatplot(c(1,2, 2,3, 3,1, 4,5))
>>
>>
>> Thanks
>> Fayez
>> Grad student UIUC
>> IL, USA
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Gabor Csardi      MTA KFKI RMKI



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] community finding in a graph and heatplot

2012-05-31 Thread Gábor Csárdi
On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez
 wrote:
>
> Hi everyone,
>
> I am using the fastgreedy.community function to get the $merges matrix and 
> the $modularity vector. This serves my purpose of testing modularity of my 
> graph. But I am "greedy" to plot the heat map and dendrrogram based on the 
> $merges dendogram matrix. I know that heatplot does the graphics part but I 
> am not sure if the dendogram generated by the heatplot will match the one 
> given by fastgreedy.community in all cases and that the heat map will 
> represent the same clustering.

No, they are different. To plot fast-greedy results as a dendrogram,
see this and the follow-ups:
http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html

Gabor

> Tell me if my apprehension is incorrect. Otherwise please let me know of any 
> alternatives. Here is the code I am testing so far:
>
> # http://igraph.sourceforge.net/doc/R/modularity.html
> # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html
> # http://igraph.sourceforge.net/doc/R/graph.constructors.html
>
> library(igraph)
> library(made4)
>
> g <- graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE)
> print(g)
> ModuleInfo <- fastgreedy.community(g)
> print(ModuleInfo)
> heatplot(c(1,2, 2,3, 3,1, 4,5))
>
>
> Thanks
> Fayez
> Grad student UIUC
> IL, USA
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with V function in igraph

2012-05-14 Thread Gábor Csárdi
Something weird must be going on in your s641_social object. Can you
just simply check that the vertex names look OK with
'V(s641_social)$name'?

If they look good, then can you send me the s641_social object in
private? (Or part of it, assuming a part is enough to reproduce the
problem.)

Best,
Gabor

On Sat, May 12, 2012 at 8:07 PM, bmccowan  wrote:
> I am using the code below to output some network measures:
>
> central_social <- data.frame(V(s641_social)$name, indegree_social,
> outdegree_social, incloseness_social, outcloseness_social,
> betweenness_social, eigen_social)
>
> and I get the following error:
>
>
> Error in Re(z) : non-numeric argument to function
>
> I know this has to do with V but I cannot figure out what is wrong.
> s641-social is a graph object and the vertices do have a name attribute.
>
> What can I do to fix?
>
> Thanks
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Help-with-V-function-in-igraph-tp4629767.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Add attributes to igraph vector by name, not index

2012-04-26 Thread Gábor Csárdi
Hi,

you can iterate over the vertices, but it'll be probably slow. The
best solution is to create the graph directly  from the data frame(s)
containing all structure and attribute data. See the
graph.data.frame() function for this.

Btw. it might be worth to post your igraph related questions to the
igraph-help mailing list if you don't get an answer here, (sadly) I am
not reading R-help frequently any more. See http://igraph.sf.net.

Best,
Gabor

On Mon, Apr 23, 2012 at 6:26 AM, cwdillon  wrote:
> Hi,
> So I've been figuring out how to use igraph in R and like it for it's speed
> and simplicity. Now I have a graph built from an edgelist where vectors have
> a $name attribute.  I have another dataframe with attributes tied to a
> vector ID, which is the same as the $name attribute of vectors represented
> in the graph.
>
> How can I iterate over the graph by V(g)$name and do set.vector.attributes
> for the other attributes in the vector dataframe?  Of course, the edgelist
> for the graph contains each vector zero or many times and they are not
> sorted in the same order as the vector dataframe.  It's a large bit of data:
> about 20m edges and 3m vectors. I can't do this by hand.
>
> Perhaps the answer is something like,
> by V(g)[]$name in g  {
>  i=get.index(V(g)$name)
>  if (V(g)[1]$name == dataframe$ID)  {
>     V(g)[1]$newattribute1 <- dataframe$attribute1
>     V(g)[1]$newattribute2 <- dataframe$attribute2
>     V(g)[1]$newattribute3 <- dataframe$attribute3
>   }
> }
>
>  R,
> CW Dillon
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Add-attributes-to-igraph-vector-by-name-not-index-tp4580032p4580032.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] On-demand importing of a package

2011-11-23 Thread Gábor Csárdi
Just for the records, the solution was to make the matrix 'dgCmatrix"
instead of 'dsCmatrix', 'dgCmatrix' works and 'dsCmatrix' does not. I
suspect that this has to do something with the S4 class hierarchy in
Matrix, but I am not sure.

This is a quite ugly workaround, since it depends on some internal
Matrix features, so I might end up just importing Matrix, as many of
you suggested in the first place

However, I agree with Gabor Grotherdieck that the issue is still
there, in general.

Another example would be (optionally) using the 'snow' (or now
'parallel') package. I would like to add optional parallel processing
to some of my functions in a package, without actually requiring the
installation of snow/parallel. If snow is there and the user wants to
use it, then it is used, otherwise not.

Actually, 'snow' works similarly. It (optionally) calls function from
the Rmpi package, but Rmpi is only suggested, there is no hard
dependency. This seems to work well for snow, but in my case I the S4
features in Matrix interfere.

Gabor

On Tue, Nov 22, 2011 at 8:09 PM, Gábor Csárdi  wrote:
> Dear Martin,
>
> thanks a lot, this all makes sense and looks great. I suspected some
> S4 trickery and totally forgot that the base package is imported
> automatically.
>
> Unfortunately I still get
>
> Error in callGeneric() :
>  'callGeneric' must be called from a generic function or method
>
> for my real function, but it works fine for the toy f() function, so I
> think I can sort this out from here.
>
> Best Regards,
> Gabor
>
> On Tue, Nov 22, 2011 at 6:57 PM, Martin Morgan  wrote:
>> On 11/22/2011 03:06 PM, Gábor Csárdi wrote:
>>>
>>> On Tue, Nov 22, 2011 at 4:27 PM, Martin Morgan  wrote:
>>> [...]
>>>>
>>>> No need to Depend:. Use
>>>>
>>>> Imports: Matrix
>>>>
>>>> plus in the NAMESPACE file
>>>>
>>>>  importFrom(Matrix, rowSums)
>>>>
>>>> Why do you not want to do this? Matrix is available for everyone,
>>>> Imports:
>>>> doesn't influence the package search path. There is a cost associated
>>>> with
>>>> loading the library in the first place, but...?
>>>
>>> Not just loading, installing a package has a cost, too. Dependencies
>>> are bad, they might make my package fail, and I have no control over
>>> them. It's not just 'Matrix', I have this issue with other packages as
>>> well.
>>>
>>> Anyway, 'Imports: Matrix' is just a workaround I think. Or is the
>>> example in my initial mail expected to fail? Why is that? Why can I
>>> call some functions from 'Matrix' that way and why can't I call
>>> others?
>>>
>>>> I'm more into black-and-white -- it either needs Matrix or not;
>>>> apparently
>>>> it does.
>>>
>>> It's a matter of opinion, I guess. I find it very annoying when I need
>>> to install a bunch of packages from which I don't use any code, just
>>> because some tiny bit of a package I need uses them. I would like to
>>> spare my users from this.
>>>
>>> [...]
>>>>
>>>> In another message you mention
>>>>
>>>>> Matrix:::rowSums(W)
>>>>
>>>> Error in callGeneric() :
>>>>  'callGeneric' must be called from a generic function or method
>>>>
>>>> but something else is going on -- you don't get to call methods directly;
>>>> you're getting Matrix::rowSums (it's exported, so no need for a :::, see
>>>> getNamespaceExports("Matrix")). Maybe traceback() after the error would
>>>> be
>>>> insightful?
>>>
>>> Another poster suggested this, that's why I tried. It is clear that I
>>> should not call it directly. All I want to do is having a function
>>> like this:
>>>
>>> f<- function() {
>>>  if (require(Matrix)) {
>>>    res<- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
>>>  } else {
>>>    res<- diag(1:5)
>>>  }
>>>  y<- rowSums(res)
>>>  res / y
>>> }
>>>
>>> Setting the subjective bit, about depending or not, aside, is there
>>> really no solution for this? The code in the manual page examples work
>>> fine without importing the package and just loading it if needed and
>>> available. Why doesn't the code within the package?
>>
>&g

Re: [R] On-demand importing of a package

2011-11-22 Thread Gábor Csárdi
Dear Martin,

thanks a lot, this all makes sense and looks great. I suspected some
S4 trickery and totally forgot that the base package is imported
automatically.

Unfortunately I still get

Error in callGeneric() :
  'callGeneric' must be called from a generic function or method

for my real function, but it works fine for the toy f() function, so I
think I can sort this out from here.

Best Regards,
Gabor

On Tue, Nov 22, 2011 at 6:57 PM, Martin Morgan  wrote:
> On 11/22/2011 03:06 PM, Gábor Csárdi wrote:
>>
>> On Tue, Nov 22, 2011 at 4:27 PM, Martin Morgan  wrote:
>> [...]
>>>
>>> No need to Depend:. Use
>>>
>>> Imports: Matrix
>>>
>>> plus in the NAMESPACE file
>>>
>>>  importFrom(Matrix, rowSums)
>>>
>>> Why do you not want to do this? Matrix is available for everyone,
>>> Imports:
>>> doesn't influence the package search path. There is a cost associated
>>> with
>>> loading the library in the first place, but...?
>>
>> Not just loading, installing a package has a cost, too. Dependencies
>> are bad, they might make my package fail, and I have no control over
>> them. It's not just 'Matrix', I have this issue with other packages as
>> well.
>>
>> Anyway, 'Imports: Matrix' is just a workaround I think. Or is the
>> example in my initial mail expected to fail? Why is that? Why can I
>> call some functions from 'Matrix' that way and why can't I call
>> others?
>>
>>> I'm more into black-and-white -- it either needs Matrix or not;
>>> apparently
>>> it does.
>>
>> It's a matter of opinion, I guess. I find it very annoying when I need
>> to install a bunch of packages from which I don't use any code, just
>> because some tiny bit of a package I need uses them. I would like to
>> spare my users from this.
>>
>> [...]
>>>
>>> In another message you mention
>>>
>>>> Matrix:::rowSums(W)
>>>
>>> Error in callGeneric() :
>>>  'callGeneric' must be called from a generic function or method
>>>
>>> but something else is going on -- you don't get to call methods directly;
>>> you're getting Matrix::rowSums (it's exported, so no need for a :::, see
>>> getNamespaceExports("Matrix")). Maybe traceback() after the error would
>>> be
>>> insightful?
>>
>> Another poster suggested this, that's why I tried. It is clear that I
>> should not call it directly. All I want to do is having a function
>> like this:
>>
>> f<- function() {
>>  if (require(Matrix)) {
>>    res<- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
>>  } else {
>>    res<- diag(1:5)
>>  }
>>  y<- rowSums(res)
>>  res / y
>> }
>>
>> Setting the subjective bit, about depending or not, aside, is there
>> really no solution for this? The code in the manual page examples work
>> fine without importing the package and just loading it if needed and
>> available. Why doesn't the code within the package?
>
> If I create a package that does not Import: Matrix (btw, Matrix is
> distributed with all R), with only a function f, and with exports(f) in
> NAMESPACE, I get
>
>> library(pkgA)
>> f()
> Loading required package: Matrix
> Loading required package: lattice
>
> Attaching package: 'Matrix'
>
> The following object(s) are masked from 'package:base':
>
>    det
>
> Error in rowSums(res) : 'x' must be an array of at least two dimensions
>
> This is because (a) Matrix is attached to the user search path but (b)
> because f is defined in the NAMESPACE of pkgA, rowSums is looked for first
> in the pkgA NAMESPACE, and in then in the search of the package (which
> includes base) and then in the user search path. It is found in base, and
> the search ends there.
>
> If I modify f to use  y <- Matrix::rowSums(res) I get
>
>> f()
> Loading required package: Matrix
> Loading required package: lattice
>
> Attaching package: 'Matrix'
>
> The following object(s) are masked from 'package:base':
>
>    det
>
> 5 x 5 sparse Matrix of class "dgCMatrix"
>
> [1,] 1 . . . .
> [2,] . 1 . . .
> [3,] . . 1 . .
> [4,] . . . 1 .
> [5,] . . . . 1
>
> I start off with the correct rowSums, and continue from there.
>
> Martin
>
>>
>> Thanks for the patience,
>> Gabor
>>
>>> Martin
>>>
>> [...]
>>
>
>
> --
> Computational Biology
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
>
> Location: M1-B861
> Telephone: 206 667-2793
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] On-demand importing of a package

2011-11-22 Thread Gábor Csárdi
On Tue, Nov 22, 2011 at 4:27 PM, Martin Morgan  wrote:
[...]
> No need to Depend:. Use
>
> Imports: Matrix
>
> plus in the NAMESPACE file
>
>  importFrom(Matrix, rowSums)
>
> Why do you not want to do this? Matrix is available for everyone, Imports:
> doesn't influence the package search path. There is a cost associated with
> loading the library in the first place, but...?

Not just loading, installing a package has a cost, too. Dependencies
are bad, they might make my package fail, and I have no control over
them. It's not just 'Matrix', I have this issue with other packages as
well.

Anyway, 'Imports: Matrix' is just a workaround I think. Or is the
example in my initial mail expected to fail? Why is that? Why can I
call some functions from 'Matrix' that way and why can't I call
others?

> I'm more into black-and-white -- it either needs Matrix or not; apparently
> it does.

It's a matter of opinion, I guess. I find it very annoying when I need
to install a bunch of packages from which I don't use any code, just
because some tiny bit of a package I need uses them. I would like to
spare my users from this.

[...]
> In another message you mention
>
>> Matrix:::rowSums(W)
> Error in callGeneric() :
>  'callGeneric' must be called from a generic function or method
>
> but something else is going on -- you don't get to call methods directly;
> you're getting Matrix::rowSums (it's exported, so no need for a :::, see
> getNamespaceExports("Matrix")). Maybe traceback() after the error would be
> insightful?

Another poster suggested this, that's why I tried. It is clear that I
should not call it directly. All I want to do is having a function
like this:

f <- function() {
 if (require(Matrix)) {
   res <- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
 } else {
   res <- diag(1:5)
 }
 y <- rowSums(res)
 res / y
}

Setting the subjective bit, about depending or not, aside, is there
really no solution for this? The code in the manual page examples work
fine without importing the package and just loading it if needed and
available. Why doesn't the code within the package?

Thanks for the patience,
Gabor

> Martin
>
[...]

-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] On-demand importing of a package

2011-11-22 Thread Gábor Csárdi
Hi Josh,

On Tue, Nov 22, 2011 at 3:31 PM, Joshua Wiley  wrote:
> Hi Gábor,
>
> You could import rowSums.  This will not fully attach Matrix.  I am
> not sure there is a really good solution for what you want to do.  To
> fully use and validate your package, Matrix appears to be required.
> This is different from simply, for example, enhancing the Matrix
> package.

importing rowSums() from NAMESPACE requires having Matrix in the
'Depends:' line, I think. I would like to avoid that, if possible.

Sure, to validate my package it is required. That is fine. For "fully"
using it might be required, but most users don't fully use a package,
they just use 1-20-50% of the functionality, depending on the size of
the package. My package does not depend on Matrix, except in less than
1% of its (quite many) functions.

> You could just write the functions assuming matrix is there, make sure
> the examples are marked don't run, and tell users if they want to use
> them, they need to load Matrix first.  I do this with OpenMx in my
> package.

Hmmm, this is close to what I want to do. Actually my functions work,
even if Matrix is not there, but they work better with Matrix. The
problem is that if I do this, then I get the error I've shown in my
initial email. I.e. Matrix is there, it is loaded, but the rowSums()
generic is not called for some reasons.

Thanks again,
Gabor

> Cheers,
>
> Josh
>
> On Tue, Nov 22, 2011 at 12:16 PM, Gábor Csárdi  wrote:
>> Dear All,
>>
>> in some functions of my package, I use the Matrix S4 class, as defined
>> in the Matrix package.
>>
>> I don't want to depend on Matrix, however, because my package is
>> perfectly fine without Matrix, most of the functionality does not need
>> Matrix. Matrix is so included in the 'Suggests' line.
>>
>> I load Matrix via require(), from the functions that really need it.
>> This mostly works fine, but I have an issue now that I cannot sort
>> out.
>>
>> If I define a function like this in my package:
>>
>> f <- function() {
>>  require(Matrix)
>>  res <- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
>>  y <- rowSums(res)
>>  res / y
>> }
>>
>> then calling it from the R prompt I get
>> Error in rowSums(res) : 'x' must be an array of at least two dimensions
>>
>> which basically means that the rowSums() in the base package is
>> called, not the S4 generic in the Matrix package. Why is that?
>> Is there any way to work around this problem, without depending on Matrix?
>>
>> I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0.
>>
>> Thank You, Best Regards,
>> Gabor
>>
>> --
>> Gabor Csardi      MTA KFKI RMKI
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> Programmer Analyst II, ATS Statistical Consulting Group
> University of California, Los Angeles
> https://joshuawiley.com/
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] On-demand importing of a package

2011-11-22 Thread Gábor Csárdi
Thanks, I have tried that, it does not work, because rowSums() calls
callGeneric():

> Matrix:::rowSums(W)
Error in callGeneric() :
  'callGeneric' must be called from a generic function or method

G.

On Tue, Nov 22, 2011 at 3:20 PM, R. Michael Weylandt
 wrote:
> How about calling Matrix's namespace directly?
>
> Matrix:::rowSums()
>
> Michael
>
> On Tue, Nov 22, 2011 at 3:16 PM, Gábor Csárdi  wrote:
>> Dear All,
>>
>> in some functions of my package, I use the Matrix S4 class, as defined
>> in the Matrix package.
>>
>> I don't want to depend on Matrix, however, because my package is
>> perfectly fine without Matrix, most of the functionality does not need
>> Matrix. Matrix is so included in the 'Suggests' line.
>>
>> I load Matrix via require(), from the functions that really need it.
>> This mostly works fine, but I have an issue now that I cannot sort
>> out.
>>
>> If I define a function like this in my package:
>>
>> f <- function() {
>>  require(Matrix)
>>  res <- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
>>  y <- rowSums(res)
>>  res / y
>> }
>>
>> then calling it from the R prompt I get
>> Error in rowSums(res) : 'x' must be an array of at least two dimensions
>>
>> which basically means that the rowSums() in the base package is
>> called, not the S4 generic in the Matrix package. Why is that?
>> Is there any way to work around this problem, without depending on Matrix?
>>
>> I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0.
>>
>> Thank You, Best Regards,
>> Gabor
>>
>> --
>> Gabor Csardi      MTA KFKI RMKI
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] On-demand importing of a package

2011-11-22 Thread Gábor Csárdi
Dear All,

in some functions of my package, I use the Matrix S4 class, as defined
in the Matrix package.

I don't want to depend on Matrix, however, because my package is
perfectly fine without Matrix, most of the functionality does not need
Matrix. Matrix is so included in the 'Suggests' line.

I load Matrix via require(), from the functions that really need it.
This mostly works fine, but I have an issue now that I cannot sort
out.

If I define a function like this in my package:

f <- function() {
  require(Matrix)
  res <- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5)
  y <- rowSums(res)
  res / y
}

then calling it from the R prompt I get
Error in rowSums(res) : 'x' must be an array of at least two dimensions

which basically means that the rowSums() in the base package is
called, not the S4 generic in the Matrix package. Why is that?
Is there any way to work around this problem, without depending on Matrix?

I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0.

Thank You, Best Regards,
Gabor

-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum cutsets

2011-10-14 Thread Gábor Csárdi
On Thu, Oct 13, 2011 at 7:47 PM, malhomidi  wrote:
> Hi again,
>
>         I've looked at the links above and I see the development version of
> the igraph library. I see the src folder implemented in C. Are these source
> codes available in R or I just would have to use the C code? The reason is
> that I just started learning R and I really want to stay away from C and
> C++.

>From the googlecode page I mentioned, you can download an R source
package, that you can compile and install in R.
Compiling it for windows is slightly more difficult, so if you need a
windows package, I can provide one.

Gabor

> Regards,
> Mohammed Alhomidi
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Minimum-cutsets-tp885346p3903287.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum cutsets

2011-10-12 Thread Gábor Csárdi
Hi Mohammed,

http://igraph.sourceforge.net/doc/R/graph.maxflow.html

For directed graphs, and s-t cuts you need the development version,
from igraph.sf.net. The source code is either here:
http://cran.r-project.org/web/packages/igraph/index.html
or here:
http://code.google.com/p/igraph/downloads/list
or here:
https://code.launchpad.net/igraph/

The development version has some big changes, e.g. vertices and edges
are numbered from 1 instead of 0. Tell me if you need a windows binary
package for the development version.

Best,
Gabor

On Wed, Oct 12, 2011 at 11:14 AM, malhomidi  wrote:
> Hi Gabor,
>
>        I'm looking for minimum cutsets in the igraph manual but I didn't
> find the functions you mentioned above. Also, how can I see their source
> code.
>
> Thanks,
> Mohammed
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Minimum-cutsets-tp885346p3898347.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plot.igraph

2011-09-29 Thread Gábor Csárdi
Dear Steven,

you have two options, one is to make the multiple edges thicker, see
the 'edge.width' argument for that.

The other is to make multiple edges curve a bit, see the 'edge.curved'
argument.
Both of these are documented at ?igraph.plotting. You can use
count.multiple() to find the edges that are multiple.
There are some examples for curved edges here:
https://lists.nongnu.org/archive/html/igraph-help/2009-03/msg00170.html

Best,
Gabor

On Thu, Sep 29, 2011 at 9:19 AM, Steven Wolf  wrote:
> I am having trouble plotting one of my graphs (think graph theory graph with
> edges and vertices, not scatterplots or histograms).  For some pairs of
> vertices, I want multiple edges to be visible in my graph.  As an example of
> this, in my script below, I want two edges to be visible from vertex 1 and
> vertex 9 (among some others) yet when I plot it, only one edge is visible.
>
> 
> gp1 = c(1,3,5,7,9)
> gp2 = c(2,4,6,8,10)
> gp3 = c(2,3,5,7)
> gp4 = c(1,4,9)
>
> adjm = numeric(100)
> dim(adjm) = c(10,10)
>
> for (i in 1:4){
>        gp = eval(as.symbol(paste("gp",i,sep="")))
>        N = length(gp)
>        for (j in 1:N){
>                for (k in j:N){
>                        adjm[gp[k],gp[j]] = adjm[gp[k],gp[j]]+1
>                        adjm[gp[j],gp[k]] = adjm[gp[k],gp[j]]
>                }
>        }
> }
> for(i in 1:10){adjm[i,i]=0}
> require(igraph)
> gg=graph.adjacency(adjm,mode="max")
>
> V(gg)$name = 1:10
> V(gg)$label = V(gg)$name
>
> plot.igraph(gg, layout=layout.kamada.kawai, vertex.color=gray(0.7))
>
> #
>
> Thanks in advance,
> -Steven Wolf
> MSU Dept of Physics
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Questons about 'igraph' package

2011-09-15 Thread Gábor Csárdi
The 'name' attribute is not used for vertex labels by default. If you
want to use it, you need to set it as the 'label' attribute as well,
or supply them in the function call:

tkplot(graph, vertex.label=V(graph)$name)

Best,
Gabor

On Wed, Sep 14, 2011 at 7:11 PM, karena  wrote:
> Hi,
>
> I am using 'igraph' to make some plots. The problem I got is that I don't
> know how to label the nodes with gene names.
>
> My sample code:
>
> ## suppose I have 100 gene (nodes) ##
> ---
> graph <- set.vertex.attribute(graph, "color",
> value=c(rep(c('green','red'),50)))
> graph <- set.vertex.attribute(graph, "name", value=genelist)
> tkplot(graph)
> 
> The 'color' attribute does work, the nodes are red and green, but the 'name'
> attribute doesn't work, I still have the numeric id on each node (0-99).
>
> Can anyone tell me how to solve this problem?
>
> Thank you,
>
> Karena
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Questons-about-igraph-package-tp3814338p3814338.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] igraph - designing graph plot by attributes

2011-08-18 Thread Gábor Csárdi
Create a factor variable for the different age categories, see cut().
Then use as.integer() on the factor variable and index a vector of
node sizes with it. E.g.

g <- graph.ring(10)
V(g)$age <- sample(20:78, vcount(g), replace=TRUE)
V(g)$agecat <- cut(V(g)$age, breaks = c(20,35,50,65,78))
V(g)$size <- c(10,15,20,25)[ V(g)$agecat ]

plot(g, layout=layout.circle)

Best,
Gabor

On Wed, Aug 10, 2011 at 1:38 PM, Gaitan, Andreea
 wrote:
> Hi,
>
> I'm working on some social networks and I managed to create the graphs with 
> labels and edges weight, but I would also like to change the size of the 
> vertices according to the age of the persons in the network and the shape 
> according to the gender. Now for the age, I have people with ages between 20 
> and 78, and I would like to have 4 categories (sizes): 20-35, 36-50, 50-65, 
> >65. I have entered the ages as attributes of the vertices from a table, so 
> they are included in the graph, but how do I change the size in the plot? And 
> the same for gender with different shapes (circle and square maybe).
>
> Thanks in advance and regards,
> Andreea.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix into vector with vertex names

2011-08-18 Thread Gábor Csárdi
Joe,

what is melt() supposed to do here?

What's wrong with the simple solution of creating a data.frame first,
and then filling it with values through a loop? Actually, keeping the
matrix is just as good, indexing is just as fast, and takes the same
amount of memory as your three column matrix, doesn't it?

Gabor

On Fri, Aug 5, 2011 at 10:40 AM, joe j  wrote:
> Using Igraph, I create shortest paths, then convert the matrix into
> three column vectors - "vertex1", "vertex2", "shortestpath" - as the
> code below shows.
>
> #code for generating shortest path matrix and creating a 3 columns
> from an igraph graph object "y"
> y_s<-shortest.paths(y,  weights = NULL)
> y_s <- melt(y_s)[melt(upper.tri(y_s))$value,] #Step 2: this is where
> the trouble with memory occurs
> y_s[,1] <- V(y)$name[y_s[,1]]
> y_s[,2] <- V(y)$name[y_s[,2]]
> names(y_s)<-c("vertex1", "vertex2", "shortestpath")
>
> However I am looking for an alternative way of doing this becase at
> the second step I run into a fight with my machine's memory. I know I
> can create vectors using as.vector(), c(), etc, but I am not able to
> create the two other columns with vertex names.
>
> Best regards,
> Joe.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix indexing (igraph ?)

2011-08-18 Thread Gábor Csárdi
This is not an igraph issue, I believe. You need to go over your
indices and update the matrix, i.e.

for (i in seq_along(t.list)) { temp[t.list[i], c.list[i]] <-
temp[t.list[i], c.list[i]] + 1 }

Best,
Gabor

On Tue, Aug 2, 2011 at 4:50 PM, Robinson, David G  wrote:
> I realize that matrix indexing has been addressed in various flavors, but I'm 
> stumped and didn't find anything in the archives.  It's not clear if it is an 
> igraph issue or a more general problem. Thanks in advance for your patience.
>
> I am using igraph to read a gml file 
> (http://www-personal.umich.edu/~mejn/netdata/football.zip
> ). The gml file contains vertex attributes (conference and team) that are 
> provided as character/integer values.
>
> I would like to build a matrix of dimension (length.team, length.conference) 
> where the elements are zero except for 1's at the location of index [team, 
> conference].
>
> Here is a snippet of code that hopefully captures what I am trying to do:
>
> original<-read.graph("./Data/football/football.gml", format="gml")
> conf.list<- get.vertex.attribute(original, 'value', index=V(original))+1
> team.list<- get.vertex.attribute(original, 'id', index=V(original))+1
> temp<- matrix(0,115,12)
> temp[team.list, conf.list]<-1
>
> Unfortunately, temp[] is filled with 1's.
>
> However, if I try:
> c.list=c(1,3,5)
> t.list=c(2,4,6)
> temp[t.list,c.list]<-1
>
> then things work as I would expect.  FWIW - I have tried 
> as.integer(get.vertex.attribute(...)) with no luck.
>
> Thanks for any suggestions.
>
>
>
>
> *
>> original<-read.graph("./Data/football/football.gml", format="gml")
>> conf.list<- get.vertex.attribute(original, 'value', index=V(original))+1
>> team.list<- get.vertex.attribute(original, 'id', index=V(original))+1
>> conf.list
>  [1]  8  1  3  4  8  4  3  9  9  8  4 11  7  3  7  3  8 10  7  2 10  9  9  8 
> 11  1  7 10 12  2  2  7  3  1  7  2  6
>  [38]  1  7  3  4  8  6  7  5  1 12  3  5 12 11  9  4 12  7  2 10  5 12 11  3 
>  7 10 11  3 10  5 12  9 11 10  7  4 12
>  [75]  4  5 10  9  9  2  6  4  6 12  4  7  5 10 12  1  6  5  5  8  2 10 10 11 
>  4  7  3  2  4  1  8  1  3  4  9  1  5
> [112]  9  5 10 12
>> team.list
>  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  
> 19  20  21  22  23  24  25  26  27
>  [28]  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45 
>  46  47  48  49  50  51  52  53  54
>  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72 
>  73  74  75  76  77  78  79  80  81
>  [82]  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 
> 100 101 102 103 104 105 106 107 108
> [109] 109 110 111 112 113 114 115
>> length(conf.list)
> [1] 115
>> length(team.list)
> [1] 115
>> temp<- matrix(0,115,12)
>> r<-c(1,3,5)
>> col<- c(2,4,6)
>> temp[r,col]<-1
>> temp[1:10,]
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
>  [1,]    0    1    0    1    0    1    0    0    0     0     0     0
>  [2,]    0    0    0    0    0    0    0    0    0     0     0     0
>  [3,]    0    1    0    1    0    1    0    0    0     0     0     0
>  [4,]    0    0    0    0    0    0    0    0    0     0     0     0
>  [5,]    0    1    0    1    0    1    0    0    0     0     0     0
>  [6,]    0    0    0    0    0    0    0    0    0     0     0     0
>  [7,]    0    0    0    0    0    0    0    0    0     0     0     0
>  [8,]    0    0    0    0    0    0    0    0    0     0     0     0
>  [9,]    0    0    0    0    0    0    0    0    0     0     0     0
> [10,]    0    0    0    0    0    0    0    0    0     0     0     0
>> temp[team.list,conf.list]<- 1
>> temp[1:10,]
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
>  [1,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [2,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [3,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [4,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [5,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [6,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [7,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [8,]    1    1    1    1    1    1    1    1    1     1     1     1
>  [9,]    1    1    1    1    1    1    1    1    1     1     1     1
> [10,]    1    1    1    1    1    1    1    1    1     1     1     1
>>
>> -
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mail

Re: [R] Watts Strogatz game

2011-05-04 Thread Gábor Csárdi
On Wed, May 4, 2011 at 9:28 AM, Robert Baer  wrote:
>>> I have a erdos-renyi game with 6000 nodes and probability 0.003.
>>>
>>> g1 = erdos.renyi.game(6000, 0.003)
>>>
>>> How to create a Watts Strogatz game with the same probability.
>>>
>>> g1 = watts.strogatz.game(1, 6000, ?, ?)
>>> What should be the third and fourth parameter to this argument.

You can work out the number of edges in a Watts-Strogatz game easily,
by calculating the degree of the nodes in the non-randomized network.
This will be different for different dimensions, of course.
Randomization does not change the average degree.

Obviously, you cannot exactly match all Erdos-Renyi graphs, because
the W-S density cannot change continuously.

Gabor

> According to ?watts.strogatz.game help file (in the igraph package?), the
> four arguments to this function are:
> dim     Integer constant, the dimension of the starting lattice.
> size     Integer constant, the size of the lattice along each dimension.
> nei     Integer constant, the neighborhood within which the vertices of the
> lattice will be connected.
> p         Real constant between zero and one, the rewiring probability.
>
> So it looks like the last two should be neighborhood and rewiring
> probability respectively.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can't use attributes from gml file in Cytoscape

2011-04-15 Thread Gábor Csárdi
Hi,

the problem is that igraph puts node colors into the GML file as
simple vertex attributes, but this is not what Cytoscape expects.
Plus, it seems that Cytoscape does not read all the node/edge
attributes from the GML file, only the ones it interprets, so the
color information is lost.

Sadly, there is no real workaround here, because Cytoscape uses
composite node attributes for storing the node color information, but
igraph cannot currently write composite node attributes to GML files.

Luckily, however, the GML file format is quite simple, so you can just
write your own GML export function:

exportGML <- function(graph, filename) {
  file <- file(filename, "w")
  cat("Creator \"igraph exportGML\"\n", file=file)
  cat("Version 1.0\n", file=file)
  cat("graph\n[\n", file=file)
  cat("  directed", as.integer(is.directed(graph)), "\n", file=file)
  for (i in seq_len(vcount(graph))) {
cat("  node\n  [\n", file=file)
cat("id", i-1, "\n", file=file)
cat("graphics\n[\n", file=file)
cat("  fill \"", V(graph)$color[i], "\"\n", sep="", file=file)
cat("  type \"rectangle\"\n", file=file)
cat("  outline \"#00\"\n", file=file)
cat("]\n", file=file)
cat("  ]\n", file=file)
  }
  el <- get.edgelist(graph, names=FALSE)
  for (i in seq_len(nrow(el))) {
cat("  edge\n  [\n", file=file)
cat("source", el[i,1], "\n", file=file)
cat("target", el[i,2], "\n", file=file)
cat("  ]\n", file=file)
  }
  cat("]\n", file=file)
  close(file)
}

You can modify it according to your needs, e.g. add layout
coordinates, etc. Look into a GML file, as exported from Cytoscape, to
see what else you can add to the file.

Best,
Gabor


On Fri, Apr 15, 2011 at 9:25 AM, Sandeep Amberkar  wrote:
> Hello,
>
> I am exporting a graph in "gml" format from igraph 0.5.5. When I open the
> file in Cytoscape v.2.7 I can't map the color attribute that I assign to the
> graph when I export it from igraph. Could anyone help me in this?
> Thanks.
>
>
> --
> Warm Regards,
> Sandeep Amberkar
> BioQuant,BQ26,
> Im Neuenheimer Feld 267,
> D-69120,Heidelberg
> Tel: +49-6221-5451354
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Questions about 'igraph' package.......

2011-03-28 Thread Gábor Csárdi
On Mon, Mar 28, 2011 at 3:12 PM, karena  wrote:
> One more question is:
>
> when you plot the gene network, you only get a number on each node, then how
> can you match the numbers to the genes?

V(g)$name gives the vertex names, in the order of vertex ids. E.g.
here is how to create a simple mapping matrix:

cbind(V(g), V(g)$name)

Best,
Gabor

> thank you very much,
>
> Karena
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Questions-about-igraph-package-tp3412734p3412745.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Questions about 'igraph' package.......

2011-03-28 Thread Gábor Csárdi
On Mon, Mar 28, 2011 at 3:05 PM, karena  wrote:
> I am using 'igraph' package to make some graphs of 'gene-gene interaction'.
>
> I can get a data.frame which has three columns.
> gene1      gene2          pvalue
> AGT         MLR            1.2e-04
> MLR         11BHSD1      1.71e-05
> IFG2        11BHSD2      2.2e-07
> .             .                 .
> .             .                 .
> .             .                 .
> AGTR1     NPPA            3.2e-2
>
> I have several questions:
> 1) How can I make a plot in which the width of the edges can represent the
> significance of the epistasis p values? I am thinking about getting another
> column which is the -log(pvalue), so the larger the value is the more
> significant the p value is.

epiG <- graph.data.frame(epitab)
coords <- layout.fruchterman.reingold(epiG, weights=-log10(E(epiG)$pvalue))
plot(epiG, layout=coords, edge.width=-log10(E(epiG)$pvalue))

> 2) After I get the graph, how can I modify the image. Because all the nodes
> in the image are numbers (0,1,.,100), how can I add the gene name to
> each node in the image?

You cannot modify the image after the plotting. Well, you can, but it
is a lot esier
to specify all the parameters at the time of the plotting:

plot(epiG, ..., vertex.label=V(epiG)$name, ...)

See ?igraph.plotting for details.

Best,
Gabor

>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Questions-about-igraph-package-tp3412734p3412734.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Merging graphs with common nodes

2011-03-23 Thread Gábor Csárdi
Hi Sandeep.

On Wed, Mar 23, 2011 at 1:03 PM, ssamberkar  wrote:
[...]
>
> A -- B in G1
>
> B -- C in G2
>
> so in G3 I would expect
>
> A -- B
>
> B -- C
>
>
> Instead I get B -- Z which baffles me.

This is because the operations are based on the internal vertex ids
and not on the vertex names. You can do two things. One is that you
permute the vertices in your graphs, so that the vertex id match, see
permute.vertices() this. The other is that you take the code from
http://lists.gnu.org/archive/html/igraph-help/2009-10/msg00087.html

Best,
Gabor

> I tried getting around this all day but couldn't come up with the resultant
> graph. I am sure I am missing something basic here but the Igraph
> documentation is not that helpful.
> Any suggestions and tips?
>
> Thanks in advance..
>
>
> --
>
> Sandeep Amberkar
>
> PhD Student,
>
> Bioquant, University of Heidelberg,Germany
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Merging-graphs-with-common-nodes-tp3400017p3400017.html
> Sent from the R help mailing list archive at Nabble.com.
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Characteristic Path length calculation

2011-03-22 Thread Gábor Csárdi
It is the same indeed.

Best,
Gabor

On Tue, Mar 22, 2011 at 7:18 PM, kparamas  wrote:
> Hi,
>
> I wish to calculate the characteristic path length of a graph.
>
> Is average.path.length(g) in 'igraph' the same as calculating the
> characteristic path length of the graph?
>
> Thanks,
> Kumar
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Characteristic-Path-length-calculation-tp3398048p3398048.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      MTA KFKI RMKI

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting Mean in plotting degree distribution

2011-03-04 Thread Gábor Csárdi
I think this would be rather something like

abline(v=mean(degree(G)))

Best,
Gabor

On Thu, Mar 3, 2011 at 8:04 PM, Scott Chamberlain
 wrote:
> library(igraph)
> G <- erdos.renyi.game(1000, 1/1000) # a random graph
>
> dd1 = degree.distribution(G)
>
> plot(dd1, xlab = "degree", ylab="frequency")
> abline(h = mean(dd1)) # the mean would be a horizontal line
>
> On Thursday, March 3, 2011 at 4:43 PM, kparamas wrote:
>> Hi,
>>
>> I am plotting degree distribution of a graph using the function,
>>
>> library(igraph)
>> dd1 = degree.distribution(G)
>>
>> plot(dd1, xlab = "degree", ylab="frequency")
>>
>> I would like to plot the mean of the distribution as a vertical line in the
>> attached plot.
>> Please let me know how to do this.
>>
>> Thanks,
>> Kumar http://r.789695.n4.nabble.com/file/n3334375/cdata3_dd.png
>> cdata3_dd.png
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Plotting-Mean-in-plotting-degree-distribution-tp3334375p3334375.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] httpd-access.log parsing and graph construction.

2011-02-01 Thread Gábor Csárdi
Hi Jeff,

I am not sure what you want to do, but the 'graph' and 'igraph'
packages are for network, graph theory, i.e.
http://en.wikipedia.org/wiki/Graph_theory

If you think that this is the kind of tool you need, look over the
manual of the packages, and the documentation at the igraph homepage
at http://igraph.sf.net to see what these packages can do for you.

Best,
Gabor

On Mon, Jan 31, 2011 at 4:23 PM, Jeff Hamann
 wrote:
> R gurus:
>
> I'm thinking about using R for website traffic analysis but didn't find 
> anything in my web searches specific to R.
>
> If I have the webpages (simple example would contain something like three (3) 
> static pages with a couple of links each) and parse the apache access log 
> file (httpd-access.log), then I can populate the graph representing the 
> website and perform whatever analysis I need. Yes?
>
> I've used the igraph package, not graph, but was assuming there's some 
> existing functionality to perform these tasks.
>
> Any thoughts? Please reply privately.
>
> Respectfully,
> Jeff.
>
>
> Jeff Hamann, PhD
> PO Box 1421
> Corvallis, Oregon 97339-1421
> 541-754-2457
> jeff.hamann[at]forestinformatics[dot]com
> jeff.d.hamann[at]gmail[dot]com
> http://www.forestinformatics.com
> http://forufus.blogspot.com/
> http://seekingalpha.com/author/jeff-d-hamann
>>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Link prediction in social network with R

2010-12-28 Thread Gábor Csárdi
Dear Eu,

On Wed, Dec 22, 2010 at 12:00 AM, EU JIN LOK  wrote:
>
> Dear R users
>
> I'm a novice user of R and have absolutely no prior knowledge of social 
> network analysis, so apologies if my question is trivial. I've spent alot of 
> time trying to solve this on my own but I really can't so hope someone here 
> can help me out. Cheers!
>
> The dataset:
> I'm trying to predict the existance of links (True or False) in a test set 
> using a training set. Both data sets are in an "edgelist" format, where User 
> IDs represents nodes in both columns with the 1st column directing to the 2nd 
> column (see figure 1 below). Using the AUC to evaluate the performance, I am 
> looking for the best algorithm to predict the existance of links in the test 
> data (50% are true and rest are false).
>
> Figure 1:
>> training
> Vertices: 1133143
> Edges: 999
> Directed: TRUE
> Edges:
>
> [0]       105 ->  850956
> [1]       105 -> 1073420
> [2]       105 -> 1102667
> [3]       165 ->  888346
> [4]       165 ->  579649
> [5]       165 ->  136665
> etc..
>
> I'm having problems obtaining the probability scores for the links / edges as 
> most of the scores are for the nodes. An example of this is the graph.knn and 
> page.rank module in igraph.
>
> So my questions are:
> 1) What do I need to do to obtain the scores for the links instead of the 
> nodes (I presume it must be a data preparation step that I must be missing 
> out)?

In general, most people are interested in the nodes of the network, so
most network indices are node level. If you want edge-level indices,
you can create another graph from yours, by transforming the edges
into vertices and vice-versa. Two vertices are connected in the new
graph, if the corresponding two edges in the old graph share an
incident vertex. However, I am sure that there are some vertex
measures that don't make sense for edges at all, so you need to be
careful with this, especially with the interpretation of the results.

Another possibility is to use the few edge-level indices, e.g. edge
betweenness, or just define analog edge measures for the existing
vertex measures.

> 2) Which R package would be the best for running the various techniques - 
> Jackard index, Adamic-Adar, common neightbours, PropFlow, etc

The first three are implemented in igraph if I remember well.

> 3) How to implement a supervised learning method such as random forest (I am 
> guessing I need to obtain a feature list but again, how can I get the scores 
> for the edges)?

I am not an expert on this, but there are are several R packages for
supervised methods, random forests as well, look around on CRAN.

I hope this helps, Best,
Gabor

> Hope I've explain my questions well but do let me know if more clarification 
> is need.
>
> Thanks in advance
> Eu Jin
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Modify the vertex label

2010-09-27 Thread Gábor Csárdi
Hi,

set the 'vertex.label.dist' parameter:

g <- graph.ring(10)
tkplot(g, vertex.label.dist=1, layout=layout.circle)

See ?igraph.plotting for details.

Best,
Gabor

On Mon, Sep 27, 2010 at 11:18 AM, anderson nuel  wrote:
> Dear r-help,
>
> I create a graph of my baysian network. I use the package igraph. The names
> of vertex are within the circle, I would leave them outside the circle?
>
>> E(g)$color <- "black"
>
>> tkplot(g, ,vertex.label=names,layout=layout.kamada.kawai,
> edge.color=E(g)$color)
>
>
> Best Regards
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting multiple edges with iGraph

2010-09-07 Thread Gábor Csárdi
Hi Sasha,

see the edge.curved graphical parameter and this message for some examples:
http://lists.gnu.org/archive/html/igraph-help/2009-03/msg00170.html

Best,
Gabor

On Sun, Sep 5, 2010 at 7:41 PM, sashaBsAs  wrote:
>
> Hello,
>
> I am working with the igraph package and I am wondering if it is possible to
> get the plot function to plot multiple edges (and multiple loops) as
> separate lines. Thanks in advance for any help on this.
>
> sasha
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Plotting-multiple-edges-with-iGraph-tp2527506p2527506.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] creation package

2010-08-26 Thread Gábor Csárdi
Dear Anderson,

please see
http://lists.nongnu.org/archive/html/igraph-help/2007-07/msg00010.html
for the solution of the 'postscript font not included' problem.

Best,
Gabor

On Wed, Aug 25, 2010 at 11:50 PM, anderson nuel  wrote:
> Dear r-help,
>
> I took your advice into consideration and i tried to solve my errors. But ,
> when I use the command R CMD check namepackage, I find an error in this file
> C:/Rpack/namepackage.Rcheck/00check.txt :
>
>
> * using log directory 'C:/Rpack/namepackge.Rcheck'
> * using R version 2.10.1 (2009-12-14)
> * using session charset: ISO8859-1
> * checking for file 'namepackge/DESCRIPTION' ... OK
> * checking extension type ... Package
> * this is package 'namepackge' version '1.0'
> * checking package name space information ... OK
> * checking package dependencies ... OK
> * checking if this is a source package ... OK
> * checking for executable files ... OK
> * checking whether package 'namepackge' can be installed ... OK
> * checking package directory ... OK
> * checking for portable file names ... OK
> * checking DESCRIPTION meta-information ... OK
> * checking top-level files ... OK
> * checking index information ... OK
> * checking package subdirectories ... OK
> * checking R files for non-ASCII characters ... OK
> * checking R files for syntax errors ... OK
> * checking whether the package can be loaded ... OK
> * checking whether the package can be loaded with stated dependencies ... OK
> * checking whether the name space can be loaded with stated dependencies ...
> OK
> * checking for unstated dependencies in R code ... OK
> * checking S3 generic/method consistency ... OK
> * checking replacement functions ... OK
> * checking foreign function calls ... OK
> * checking R code for possible problems ... OK
> * checking Rd files ... OK
> * checking Rd metadata ... OK
> * checking Rd cross-references ... OK
> * checking for missing documentation entries ... OK
> * checking for code/documentation mismatches ... OK
> * checking Rd \usage sections ... OK
> * checking data for non-ASCII characters ... OK
> * checking examples ... ERROR
> Running examples in 'namepackge-Ex.R' failed.
> The error most likely occurred in:
>
>> ### * RT
>>
>> flush(stderr()); flush(stdout())
>>
>> ### Name: RT
>> ### Title: modeling
>> ### Aliases: RT
>> ### Keywords: programming models
>>
>> ### ** Examples
>>
>>   data(d)
>>   data <- d
>> RT(t(d), c(2,2,2), c(1,2,3),c("V1","V2","V3"))
> Error in text.default(x, y, labels = labels, col = label.color, family =
> label.family,  :
>  family 'serif' not included in PostScript device
> Calls: RT-> plot -> plot.igraph -> text -> text.default
> Execution halted
> Best Regards,

[...]

-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] send out put to file in R

2010-07-16 Thread Gábor Csárdi
On Thu, Jul 15, 2010 at 6:38 PM, chakri_amateur  wrote:
[...]
> I want to extract the largest connected component (alias sub-graph) of the
> network. My input network is a large network of >1000 vertices and >15000
> arcs. From this, I want to take out only the largest cluster.
>
>> If you decompose a graph to components, you get a list of graphs;
>
> Yes. But I want only the largest sub-graph. It is first in the list
> sub-graphs generated. Am I right ? I tried with 10 files, and all the time
> the largest sub-graph is shown first in the list. (i.e i=1, in compo[[i]])

No, this is not right. It is just a coincidence. The components are
not ordered. In fact, the first component in the list is the one that
has the first (well, zeroth) vertex. Check the sizes of the components
and explicitly choose the largest one:

compo[[ which.max(sapply(compo, vcount)) ]]

Best,
Gabor

>> for (i in seq_along(compo)) {
>>   write.graph(compo[[i]], file=paste(sep="", "new-", i, ".net"),
>> format="pajek")
>> }
>
> It worked. I Just had to give entire file path instead of just "new" !
>
> for (i in seq_along(compo)) {
> write.graph(compo[[i]], file=paste(sep="", "F://new-", i, ".net"), "pajek")
> }
>
> or For the first component
> write.graph(compo[[1]], "F://new.net", "pajek")
>
> Chakri
>
>
>
>
> Second,
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/send-out-put-to-file-in-R-tp2288515p2290393.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] send out put to file in R

2010-07-14 Thread Gábor Csárdi
On Thu, Jul 15, 2010 at 7:24 AM, chakri_amateur  wrote:
[...]
> wri write.graph ("F://new", "pajek") <-      decompose.graph(g,  mode="weak", 
> max.comps=NA,
> min.vertices= 20)
>
>
> But even that doesn't work

No wonder, writing computer programs is not just typing in random
words and let the computer figure out what you are trying to do. At
least not yet.

> Is there a way in which I could convert my output to a graph ?

But you already have that in "test.net", no?

It would help if you could tell us what you are trying to do. If you
decompose a graph to components, you get a list of graphs; do you want
to save each component in a separate file? Then do this (untested):

for (i in seq_along(compo)) {
  write.graph(compo[[i]], file=paste(sep="", "new-", i, ".net"), format="pajek")
}

If you want to do something else, then please tell us.

Gabor

> Regards
> Chakri
>
> --- On Wed, 14/7/10, Peter Ehlers [via R] 
>  wrote:
>
> From: Peter Ehlers [via R] 
> Subject: Re: send out put to file in R
> To: "chakri_amateur" 
> Date: Wednesday, 14 July, 2010, 6:23 PM
>
>
>
>
> On 2010-07-14 4:04, chakri_amateur wrote:
>
>>
>
>> Hi
>
>>
>
>> I am using igraph package in R.
>
>> My goal is to read  a network (in "pajek" format) and decompose the network
>
>> into components.
>
>> In addition, I am also interested in sending this output to to a file.
>
>>
>
>> I am having problem in while writing to a file!
>
>>
>
>> my code looks like this
>
>> g<- read.graph ("F://test.net", "pajek")
>
>> compo<- decompose.graph(g,  mode="weak", max.comps=NA, min.vertices= 20)
>
>> write.graph (compo, "F://new", "pajek")
>
>>
>
>> The error message shown up was -- "Not a Graph Object"
>
>>
>
>> Could any one explain what is the problem here ?
>
> Sure: compo is not an igraph object; it's a list as
>
> class(compo) or reading the help page for decompose.graph
>
> would tell you.
>
>
>    -Peter Ehlers
>
>
>>
>
>> Thanks
>
>> chakri
>
>
> __
>
> [hidden email] mailing list
>
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>
>
> View message @ 
> http://r.789695.n4.nabble.com/send-out-put-to-file-in-R-tp2288515p2288693.html
>
>
> To unsubscribe from send out put to file in R, click here.
>
>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/send-out-put-to-file-in-R-tp2288515p2289690.html
> Sent from the R help mailing list archive at Nabble.com.
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Gabor Csardi      UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] S3 generics need identical signature?

2010-06-21 Thread Gábor Csárdi
On Mon, Jun 21, 2010 at 4:17 PM, Duncan Murdoch
 wrote:
[...]
> The requirement is that the methods need to have signatures that contain all
> the arguments of the generic.  If the generic includes ..., then the methods
> can add other arguments, too.  So with the generic for plot() as you show
> above, any plot method is required to have x and y as the first two
> arguments, and ... as an argument, but they can have other args too.

This makes sense, and it is actually great! Thanks a lot for the explanation.

Best Regards,
Gabor

[...]


-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] S3 generics need identical signature?

2010-06-21 Thread Gábor Csárdi
Dear all,

"Writing R Extensions" explicitly says that

A method must have all the arguments of the generic, including ...
if the generic does.
A method must have arguments in exactly the same order as the generic.
If the generic specifies defaults, all methods should use the same
defaults.

This is clear. R CMD check even checks for this.

But then how is it possible that for plot(), which is an S3 generic,
plot.default(), plot.formula() and plot.table(), etc. all have
different arguments?

The question is not simply theoretical, I have two S3 generics in my
package, and one is reported by R CMD check, but the other not, and I
fail to see why the difference.

Moreover, R CMD check reports:
* checking S3 generic/method consistency ... WARNING
plot:
  function(x, ...)
plot.communities:
  function(communities, graph, colbar, col, mark.groups, layout,
   edge.color, ...)

But actually, the signature of plot() seems to be
> plot
function (x, y, ...)
[...]

I am confused. What am I missing?

Thanks, Best Regards,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Package testing

2010-06-15 Thread Gábor Csárdi
Duncan,

thanks, if the header is skipped, then it is much better.

It seems that I will be able to run the tests without actually running
'R CMD check' and extract the results, so it all looks good now.

Best Regards,
Gabor

On Tue, Jun 15, 2010 at 7:25 PM, Duncan Murdoch
 wrote:
> Gábor Csárdi wrote:
>>
>> Dear all,
>>
>> I would like to write some tests for my R package, and the usual
>> 'tests' directory seemed like a good solution, but there is something
>> I cannot understand.
>>
>> It is possible to supply .Rout.save files with the expected output for
>> the tests, which is great. But since the tests are not run with R
>> --slave, the expected output needs to contain all the extra output
>> from R, e.g. the startup message. The commands are echoed to the
>> output, too.
>>
>> This makes it difficult to write proper tests, as they will
>> necessarily fail on all but one R versions (the version number is
>> always part of the output), and one would need to write the test
>> programs twice, once in the normal .R file, and once in the .Rout.save
>> file.
>>
>> Is there a way to work around these things? Or am I trying to use the
>> 'tests' directory for something that was not intended?
>>
>
> The normal workflow is to write the tests as R files, and run them.  Then
> manually check every line of the Rout, and when you're satisfied it's fine,
> save it as an Rout.save file.  After that R will only report changes to that
> file that occur after the header, so version numbering changes will be
> ignored, but changes that affect your output will not.
>
> Duncan Murdoch
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Package testing

2010-06-15 Thread Gábor Csárdi
Dear all,

I would like to write some tests for my R package, and the usual
'tests' directory seemed like a good solution, but there is something
I cannot understand.

It is possible to supply .Rout.save files with the expected output for
the tests, which is great. But since the tests are not run with R
--slave, the expected output needs to contain all the extra output
from R, e.g. the startup message. The commands are echoed to the
output, too.

This makes it difficult to write proper tests, as they will
necessarily fail on all but one R versions (the version number is
always part of the output), and one would need to write the test
programs twice, once in the normal .R file, and once in the .Rout.save
file.

Is there a way to work around these things? Or am I trying to use the
'tests' directory for something that was not intended?

Best Regards,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fit a line to power law distribution

2010-04-21 Thread Gábor Csárdi
Hi,

perhaps the example at
http://igraph.sourceforge.net/screenshots2.html#8
helps.

Best,
Gabor

On Tue, Apr 20, 2010 at 6:42 PM, Narges Zarabi  wrote:
> Hi,
>
> I am trying to fit a line in the log plot of my networks degree distribution
> to show that it is a power-law distribution. I am using the following
> commands. However, I am not able to see the fitted line. Any comments to
> help?
> I am using following packages: igraph, splines,base,VGAM, netmodels.
> g is my network, d is the degree of nodes in the network, and dd is the
> degree distribution
>
> d <-degree(g)
> dd <- degree.distribution(g)
> fit plot(dd,log="xy")
> abline(fit)
>
> Thanks in advance.
> Regards, *Narcissus*
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Biclustering package

2010-02-11 Thread Gábor Csárdi
Alex, the isa2 package implements the biclustering algorithm discussed in
Bergmann S, Ihmels J, and Barkai N. Iterative signature algorithm for
the analysis of large-scale gene expression data. Phys Rev E Stat
Nonlin Soft Matter Phys 2003 Mar; 67(3 Pt 1) 031902

Best,
Gabor

On Thu, Feb 11, 2010 at 10:51 AM, Alex Roy  wrote:
> Hello,
>           I am looking for R package which can perform biclustering a part
> from biclust package.
>
> thanks
>
> Alex
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] pickle in R

2010-02-03 Thread Gábor Csárdi
On Thu, Feb 4, 2010 at 12:20 AM, Frank E Harrell Jr
 wrote:
> Gábor Csárdi wrote:
>>
>> Perhaps you are looking for ?serialize.
>>
>> Best,
>> Gábor
>
> Wouldn't save( ) and load( ) be faster and result in much smaller files?

Depends, functionality is not the same, I think. 'serialize' can
simply return the serialized form of an object, 'save' works best with
files. (With some extra work it should work on general connections I
suppose.) 'save' can handle many objects, serialize works with a
single object. I'm sure there are other differences.

Gabor

> Frank
>
>>
>> On Thu, Feb 4, 2010 at 12:09 AM, mkna005 mkna005
>>  wrote:
>>>
>>> Hello all!
>>> I was wondering if there is a way to pickle an R object into a file
>>> like it is possible in python? Such as you have an complicated R
>>> object(not a dataframe) , you use a function to write it to a file and
>>> than you have a function where you can retrieve the object from that
>>> file later on.
>>>
>>> Thanks
>>>
>>> Christoph
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>
>
> --
> Frank E Harrell Jr   Professor and Chairman        School of Medicine
>                     Department of Biostatistics   Vanderbilt University
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] pickle in R

2010-02-03 Thread Gábor Csárdi
Perhaps you are looking for ?serialize.

Best,
Gábor

On Thu, Feb 4, 2010 at 12:09 AM, mkna005 mkna005
 wrote:
> Hello all!
> I was wondering if there is a way to pickle an R object into a file
> like it is possible in python? Such as you have an complicated R
> object(not a dataframe) , you use a function to write it to a file and
> than you have a function where you can retrieve the object from that
> file later on.
>
> Thanks
>
> Christoph
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Biclustering / Co-clustering in more than 2 dimensions

2010-02-02 Thread Gábor Csárdi
Hi Tim,

maybe you are looking for something like this:
http://www.nature.com/nbt/journal/v26/n5/full/nbt1397.html
It is relatively easy to implement in R, I think.

Best,
Gabor

On Tue, Feb 2, 2010 at 3:44 PM, Tim Smith  wrote:
> Hi,
>
> I was wondering if there existed a package in R that would bicluster / 
> co-cluster in more than 2 dimensions.
> thanks!
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R igraph clusters component

2009-12-04 Thread Gábor Csárdi
Hi,

On Fri, Dec 4, 2009 at 3:12 AM, Gaurav Kumar  wrote:
> Hi R-users,
>
> I'm using igraph for an undirected graph.
> i used clusters() igraph function to know the component size(subgraphs) as 
> shown bellow:
> c <-clusters(g)
> # component sizes
> size <- sort(c$csize, decreasing=TRUE)
> cat("Top 20 cluster of the graph","\n")
> for (i in 1:20)
> {
>   cat(i,"  size:",size[i] ,"\n")
> }
>
> Can anyone help how to extract the subgraph components  based on the size as  
> edgelist-format.

V(g)$name <- seq_len(vcount(g))-1
lapply(head(order(c$csize, decreasing=TRUE), 20), g, c$membership,
FUN=function(w, g, m) {
  get.edgelist(subgraph(g, which(m==w-1)-1))
})

This gives you the largest 20 components. Best,
Gabor

ps. there is also an igraph-help mailing list, see
http://igraph.sf.net. Just in case you get no answer on R-help.

> Thanks in advance
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Exact String Compare in R?

2009-11-03 Thread Gábor Csárdi
On Tue, Nov 3, 2009 at 2:41 PM, bamsel  wrote:
>
> Dear R users:
> Here's a barebones example of what I can't make work.
> As you can see, regexpr() does not perform an exact string match, which only
> occurs in row 1 of these data frames. Instead, as it's supposed to do, it
> finds "b" in "bb" and "c" in "cc". Does anybody know what function I can use
> such that only the first rows would be matched (ie, exact string match?)
> I've also tried simply using the == operator, in which case i get the
> error:"level sets of factors are different"

Because they are not strings, but factors. Convert them to strings
with as.character and use "==".

Best,
Gabor

> Thank you in advance,
> B
>
>> ## two toy data frames, containing character arrays
>> D1=as.data.frame(c("a","b","c"))
>> D2=as.data.frame(c("a","bb","cc"))
>>
>> ## loop through each comparing the strings in each row
>> i=1 #counter
>> while (regexpr(D1[i,1], D2[i,1]) == TRUE) {
> +        cat("identical match on row #", i, "\n")
> +        i=i+1
> +         if (i>3) break
> + }
> identical match on row # 1
> identical match on row # 2
> identical match on row # 3
> --
> View this message in context: 
> http://old.nabble.com/Exact-String-Compare-in-R--tp26160122p26160122.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] random numbers between 0 and 1

2009-10-21 Thread Gábor Csárdi
I would suggest to use the generator at
http://submoon.freeshell.org/pix/valium/dilbert_rng.jpg
and subtract 8.5.

Best,
Gabor


On Wed, Oct 21, 2009 at 9:25 PM, carol white  wrote:
> Hi,
> To generate random numbers between 0 and 1, do you use rnorm followed by 
> dnrom? for ex, for 10 variables
>
> a = rnorm(10)
>> a
>  [1] -0.87640764 -0.95842391 -1.33434559 -0.63844932 -1.69829393  0.80010865
>  [7] -0.01026882 -0.23887516  2.29912600 -1.38352143
>> dnorm(a)
>  [1] 0.27171985 0.25202507 0.16378878 0.32538464 0.09432211 0.28966637
>  [7] 0.39892125 0.38772103 0.02838403 0.15320103
>
>
> Regards,
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Legend

2009-10-02 Thread Gábor Csárdi
On Fri, Oct 2, 2009 at 3:46 PM, Ashta  wrote:
> I have more than three lines in one  and I want to add a legend  for each
> line
>
> abline( m1, col = 'red' )
> ablime( m2, col = 'blue' )
> abline( m3, col = 'purple' )
>
> How can I add a legend? .

Surprisingly, it is the legend() function. See ?legend.

>  Is it also possible to increase the thickness of
> the lines?

It is, see the 'lwd' parameter in ?par.

Best,
Gabor

> Thanks
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Rd files, \itemize in \value

2009-10-02 Thread Gábor Csárdi
Dear All,

how can I create a list in the \value{} section of an Rd file? The
things I have tried:

1.

\value{
text text
\item more text
\item even more
}

*** Syntax error: \item in
/-
\item more text
\item even more\-

2.

\value{
text text
\item{more text}
\item{even more}
}

This gives no error or warning, but the manual page looks as

Value:
 text text

more text: Numeric scalar giving the minimum correlation for
  convergence.

even more: Numeric scalar giving the minimum correlation for
  convergence.


The "Numeric..." text is coming from the last \item{} in arguments{}...

3.

\value{
text text
\itemize{
\item{more text}
\item{even more}
}
}

Gives the same result as 2, but with a warning

Is there a proper way?

Thanks,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Compress (gzip) a pdf device

2009-10-02 Thread Gábor Csárdi
Rainer,

if you are willing to patch the R source, then a solution might be the
R connection patch, see
http://wiki.r-project.org/rwiki/doku.php?id=developers:r_connections_api
It is a bit outdated, but with a little work I could use it for R
2.9.2 and works fine.

Best,
Gabor

On Fri, Oct 2, 2009 at 8:54 AM, Rainer M Krug  wrote:
> On Thu, Oct 1, 2009 at 7:26 PM, Martin Renner <
> martin.ren...@stonebow.otago.ac.nz> wrote:
>
>> try pdftk. Not quite on the fly but should do the trick. (I saw this on
>> this list a little while ago)
>>
>
> pdftk compresses the pdf internally - it is still a pdf, can be opened as a
> pdf, and is not an externally compressed pdf (pdf in an archive).
> Below is the approach which I am using, but as stated earlier, if somebody
> could provide a way of only doing dev.off() whhich then calls pdfComp() with
> the filename, I would be glad to know. Otherwise.
>
> Rainer
>
>
>>
>> pdfComp <- function (pdfname){
>>  if (0){
>>    x <- tempfile()
>>    system (paste ("mv", pdfname, x))
>>    system (paste ("pdftk", x, "output", pdfname, "compress"))
>>    unlink (x)
>>  }
>> }
>>
>> pdf ("test.pdf")
>> plot (1:10)
>> dev.off()
>> pdfComp ("test.pdf")
>>
>>
>> On 30 Sep 2009, at 00:25 , Rainer M Krug wrote:
>>
>>  2009/9/30 Daniele Amberti 
>>>
>>>  I have not found an easy way to compress a file on filesystem.
 Especially I'd like to compress a pdf from pdf() function/device. Is it
 possible to compress It on the flight?
 I'd like to do something like:
 pdf(gzipconnection())
 dev.off()


  I guess this boils down to a question I asked some time ago concerning
>>> getting the filename of a pdf() device, as I wanted to create a compressed
>>> pdf from the uncompressed pdf created by R (not "zipping" the pdf).
>>> It does not seem to be possible, at least I did not get any response which
>>> I
>>> could use to implement my idea (create my dev.off(), which calls dev.off()
>>> and afterwards compresses the pdf by using the file name).
>>>
>>> If you find a solution, please let me know.
>>>
>>> Cheers,
>>>
>>> Rainer
>>>
>>> If It is not possible, how can I create a gzip with the pdf?
>>>

 Thanks
 Daniele A.



 
 ORS Srl

 Via Agostino Morando 1/3 12060 Roddi (Cn) - Italy
 Tel. +39 0173 620211
 Fax. +39 0173 620299 / +39 0173 433111
 Web Site www.ors.it



 
 Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi
 allegati ? vietato e potrebbe costituire reato.
 Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo grati se
 provvedesse alla distruzione dello stesso
 e degli eventuali allegati.
 Opinioni, conclusioni o altre informazioni riportate nella e-mail, che
 non
 siano relative alle attivit? e/o
 alla missione aziendale di O.R.S. Srl si intendono non attribuibili alla
 societ? stessa, n? la impegnano in alcun modo.

      [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


>>>
>>>
>>> --
>>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>>> Biology,
>>> UCT), Dipl. Phys. (Germany)
>>>
>>> Centre of Excellence for Invasion Biology
>>> Natural Sciences Building
>>> Office Suite 2039
>>> Stellenbosch University
>>> Main Campus, Merriman Avenue
>>> Stellenbosch
>>> South Africa
>>>
>>> Cell:           +27 - (0)83 9479 042
>>> Fax:            +27 - (0)86 516 2782
>>> Fax:            +49 - (0)721 151 334 888
>>> email:          rai...@krugs.de
>>>
>>> Skype:          RMkrug
>>> Google:         r.m.k...@gmail.com
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
>
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
> UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Natural Sciences Building
> Office Suite 2039
> Stellenbosch University
> Main Campus, Merriman Avenue
> Stellenbosch
> South Africa
>
> Cell:           +27 - (0)83 9479 042
> Fax:            +27 - (0)86 516 2782
> Fax:            +49 - (0)721 151 334 888
> email:          rai...@krugs.de
>
> Skype:          RMkrug
> Google:         r.m.k...@gmail.com
>
>        [[alternative HTML version deleted]]
>
> 

Re: [R] preformatted and '#' in manual pages

2009-09-30 Thread Gábor Csárdi
On Wed, Sep 30, 2009 at 10:51 PM, Duncan Murdoch  wrote:
> On 9/29/2009 7:31 AM, Gábor Csárdi wrote:
>>
>> Uwe, thanks, but this does not help, I still get:
>>
>> LaTeX errors when creating PDF version.
>> This typically indicates Rd problems.
>> LaTeX errors found:
>> ! You can't use `macro parameter character #' in vertical mode.
>>  ...ike the following: \begin {alltt} ##
>>                                                   vertex1name vertex2name
>> [...
>> l.9051 listed one per line on subsequent lines.}
>>
>> * checking PDF version of manual without index ... ERROR
>>
>> In fact, I added the '\' after the package check failed, but it made
>> no visible difference.
>>
>> Best,
>> Gabor
>
>
> I think this is an inconsistency between LaTeX versions.  On my system, the
> version with no \ on the # works fine, and the documentation for alltt (the
> LaTeX environment used for \preformatted) says it should.
>
> However, R 2.9.2 did add an escape on the #, and that also works fine on my
> system, so I'm going to get R 2.10.0 to add the backslash again. Hopefully
> this will fix things on your system, leave them okay on mine, and not break
> someone else's.

Yep, this sound good, thanks for the help. Btw. it is the LaTeX
version on the windows build service server that gives the error
messages, I haven't tried 2.10.0 on my Linux box yet.

Best,
Gabor

> Duncan Murdoch
>
>> 2009/9/29 Uwe Ligges :
>>>
>>> From Writing R Extensions:
>>>
>>> "‘#’, ‘_’ and ‘&’ must not be escaped."
>>>
>>> Uwe Ligges
>>>
>>>
>>>
>>>
>>>
>>> Gábor Csárdi wrote:
>>>>
>>>> Dear All,
>>>>
>>>> I have the following in a .Rd file:
>>>> ...
>>>>     human readable (not binary) format. The format itself is like
>>>>     the following:
>>>>     \preformatted{
>>>>       \# vertex1name
>>>>       vertex2name [optionalWeight]
>>>>       vertex3name [optionalWeight]
>>>>     }
>>>>     Here, the first vertex of an edge is preceded with a pound sign
>>>> ...
>>>>
>>>> and it is fine with R 2.9.2, but fails on R-devel, when building the
>>>> PDF version of the manual:
>>>> ...
>>>> * checking PDF version of manual ... WARNING
>>>> LaTeX errors when creating PDF version.
>>>> This typically indicates Rd problems.
>>>> LaTeX errors found:
>>>> ! You can't use `macro parameter character #' in vertical mode.
>>>>  ...ike the following: \begin {alltt} ##
>>>>                                                  vertex1name vertex2name
>>>> [...
>>>> l.9051 listed one per line on subsequent lines.}
>>>>
>>>> * checking PDF version of manual without index ... ERROR
>>>>
>>>> To be precise, this is
>>>> * using R version 2.10.0 Under development (unstable) (2009-09-27
>>>> r49847)
>>>>
>>>> Is there a way to escape the '#' for LaTeX?
>>>>
>>>> Thanks,
>>>> Gabor
>>>>
>>>
>>
>>
>>
>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] preformatted and '#' in manual pages

2009-09-30 Thread Gábor Csárdi
On Tue, Sep 29, 2009 at 6:47 PM, Duncan Murdoch  wrote:
> On 9/29/2009 11:57 AM, Gábor Csárdi wrote:
>>
>> On Tue, Sep 29, 2009 at 5:36 PM, Duncan Murdoch 
>> wrote:
>>>
>>> Gábor Csárdi wrote:
>>>>
>>>> Dear All,
>>>>
>>>> I have the following in a .Rd file:
>>>> ...
>>>>     human readable (not binary) format. The format itself is like
>>>>     the following:
>>>>     \preformatted{
>>>>       \# vertex1name
>>>>       vertex2name [optionalWeight]
>>>>       vertex3name [optionalWeight]
>>>>     }
>>>>     Here, the first vertex of an edge is preceded with a pound sign
>>>> ...
>>>>
>>>> and it is fine with R 2.9.2, but fails on R-devel, when building the
>>>> PDF version of the manual:
>>>> ...
>>>> * checking PDF version of manual ... WARNING
>>>> LaTeX errors when creating PDF version.
>>>> This typically indicates Rd problems.
>>>> LaTeX errors found:
>>>> ! You can't use `macro parameter character #' in vertical mode.
>>>>  ...ike the following: \begin {alltt} ##
>>>>                                                  vertex1name vertex2name
>>>> [...
>>>> l.9051 listed one per line on subsequent lines.}
>>>>
>>>> * checking PDF version of manual without index ... ERROR
>>>>
>>>> To be precise, this is
>>>> * using R version 2.10.0 Under development (unstable) (2009-09-27
>>>> r49847)
>>>>
>>>> Is there a way to escape the '#' for LaTeX?
>>>
>>> I believe the Latex macro you want is \sharp, which isnt an Rd macro, so
>>> you'd need something like
>>> \latex{\sharp}{#}.
>>
>> Duncan,
>>
>> this might solve the issue in Latex (I haven't tried yet), but in R
>> (version 2.9.2) the manual page looks like
>> ...
>>        is like the following:
>>
>>                \latex{\sharp}{#} vertex1name
>>                vertex2name [optionalWeight]
>>                vertex3name [optionalWeight]
>>
>>        Here, the first vertex of an edge is preceded with a pound sign
>> ...
>>
>> which is obviously not what I want.
>
>
> I guess that's still in the \preformatted section, which doesn't act on Rd
> macros.  Sorry about that, my advice assumed you were putting it into text.
>
> Did 2.9.x emit the \sharp in this situation, or did it do something else?
>  We do some rewriting of special characters when writing verbatim text, and
> it looks as though our handling of # has changed.  (I'm just heading out to
> a long meeting, or I'd check myself...)
>
> Duncan Murdoch
>

Yes, that was 2.9.x. This part might be OK for R-devel (I don't know,
I am using the windows build service to check with R-devel, but have
no windows at hand to install the package).

But, anyway, R-devel check fails if there is a '#' in the
\preformatted section in all these situations:
- plain #
- escaped \#
- \latex{\sharp}{#}

Best,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] preformatted and '#' in manual pages

2009-09-29 Thread Gábor Csárdi
On Tue, Sep 29, 2009 at 5:36 PM, Duncan Murdoch  wrote:
> Gábor Csárdi wrote:
>>
>> Dear All,
>>
>> I have the following in a .Rd file:
>> ...
>>      human readable (not binary) format. The format itself is like
>>      the following:
>>      \preformatted{
>>        \# vertex1name
>>        vertex2name [optionalWeight]
>>        vertex3name [optionalWeight]
>>      }
>>      Here, the first vertex of an edge is preceded with a pound sign
>> ...
>>
>> and it is fine with R 2.9.2, but fails on R-devel, when building the
>> PDF version of the manual:
>> ...
>> * checking PDF version of manual ... WARNING
>> LaTeX errors when creating PDF version.
>> This typically indicates Rd problems.
>> LaTeX errors found:
>> ! You can't use `macro parameter character #' in vertical mode.
>>  ...ike the following: \begin {alltt} ##
>>                                                   vertex1name vertex2name
>> [...
>> l.9051 listed one per line on subsequent lines.}
>>
>> * checking PDF version of manual without index ... ERROR
>>
>> To be precise, this is
>> * using R version 2.10.0 Under development (unstable) (2009-09-27 r49847)
>>
>> Is there a way to escape the '#' for LaTeX?
>
> I believe the Latex macro you want is \sharp, which isnt an Rd macro, so
> you'd need something like
> \latex{\sharp}{#}.

Duncan,

this might solve the issue in Latex (I haven't tried yet), but in R
(version 2.9.2) the manual page looks like
...
is like the following:

\latex{\sharp}{#} vertex1name
vertex2name [optionalWeight]
vertex3name [optionalWeight]

Here, the first vertex of an edge is preceded with a pound sign
...

which is obviously not what I want.

Gabor

> Duncan Murdoch
>

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] preformatted and '#' in manual pages

2009-09-29 Thread Gábor Csárdi
Uwe, thanks, but this does not help, I still get:

LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! You can't use `macro parameter character #' in vertical mode.
 ...ike the following: \begin {alltt} ##
   vertex1name vertex2name [...
l.9051 listed one per line on subsequent lines.}

* checking PDF version of manual without index ... ERROR

In fact, I added the '\' after the package check failed, but it made
no visible difference.

Best,
Gabor

2009/9/29 Uwe Ligges :
> From Writing R Extensions:
>
> "‘#’, ‘_’ and ‘&’ must not be escaped."
>
> Uwe Ligges
>
>
>
>
>
> Gábor Csárdi wrote:
>>
>> Dear All,
>>
>> I have the following in a .Rd file:
>> ...
>>      human readable (not binary) format. The format itself is like
>>      the following:
>>      \preformatted{
>>        \# vertex1name
>>        vertex2name [optionalWeight]
>>        vertex3name [optionalWeight]
>>      }
>>      Here, the first vertex of an edge is preceded with a pound sign
>> ...
>>
>> and it is fine with R 2.9.2, but fails on R-devel, when building the
>> PDF version of the manual:
>> ...
>> * checking PDF version of manual ... WARNING
>> LaTeX errors when creating PDF version.
>> This typically indicates Rd problems.
>> LaTeX errors found:
>> ! You can't use `macro parameter character #' in vertical mode.
>>  ...ike the following: \begin {alltt} ##
>>                                                   vertex1name vertex2name
>> [...
>> l.9051 listed one per line on subsequent lines.}
>>
>> * checking PDF version of manual without index ... ERROR
>>
>> To be precise, this is
>> * using R version 2.10.0 Under development (unstable) (2009-09-27 r49847)
>>
>> Is there a way to escape the '#' for LaTeX?
>>
>> Thanks,
>> Gabor
>>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] preformatted and '#' in manual pages

2009-09-29 Thread Gábor Csárdi
Dear All,

I have the following in a .Rd file:
...
  human readable (not binary) format. The format itself is like
  the following:
  \preformatted{
\# vertex1name
vertex2name [optionalWeight]
vertex3name [optionalWeight]
  }
  Here, the first vertex of an edge is preceded with a pound sign
...

and it is fine with R 2.9.2, but fails on R-devel, when building the
PDF version of the manual:
...
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! You can't use `macro parameter character #' in vertical mode.
 ...ike the following: \begin {alltt} ##
   vertex1name vertex2name [...
l.9051 listed one per line on subsequent lines.}

* checking PDF version of manual without index ... ERROR

To be precise, this is
* using R version 2.10.0 Under development (unstable) (2009-09-27 r49847)

Is there a way to escape the '#' for LaTeX?

Thanks,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Ford Fulkerson

2009-09-23 Thread Gábor Csárdi
Hi,

with a different (faster) algorithm, but maximum flows are implemented
in package igraph, although for some networks only calculating the
flow value is supported, giving the flow itself is not.

Best,
Gabor

On Wed, Sep 23, 2009 at 3:37 AM, shuva gupta  wrote:
> Hi,
> Is there any R implementation of the well-known algorithm from the Operations 
> Research
> literature, the Ford-Fulkerson algorithm of maximum flow in networks with 
> capacities.
> Thanks.
>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why S4 method is not visible from another package?

2009-09-18 Thread Gábor Csárdi
On Thu, Sep 17, 2009 at 5:59 PM, Martin Morgan  wrote:
> Gábor Csárdi wrote:
>> Dear All,
>>
>> maybe this is something obvious, I seem to be incapable of
>> understanding how S4 works.
>>
>> So, in package 'A' I defined a "summary" method for my class:
>>
>> setMethod("summary", signature(object="ListHyperGResult"),
>>           function(object, pvalue=pvalueCutoff(object), categorySize=NULL) {
>>              "whatever"
>>           })
>>
>> "ListHyperGResult" has a subclass, "GOListHyperGResult":
>>
>> setClass("GOListHyperGResult",
>>          representation=representation(conditional="logical"),
>>          contains="ListHyperGResult",
>>          prototype=prototype(testname="GO"))
>>
>> The summary method is exported in the NAMESPACE:
>>
>> exportMethods("summary")
>>
>> Package 'B' depends on package 'A', this is stated in the
>> 'DESCRIPTION' file. If I call 'summary' on a 'GOListHyperGResult' in
>
> Hi Gabor
>
> It is not S4 alone, but S4 + name spaces that are giving you problems.
>
> You probably want to Import: A rather than depends, and importFrom(A,
> summary).
>
> As it stands, inside the B name space, you find base::summary, whereas
> you've defined a method on summary that has been promoted to a generic
> in one of the packages that A imports (probably AnnotationDbi).
>
> This is a little bit of a guess; at some level it might seem more
> appropriate to Import: AnnotationDbi and importFrom(AnnotationDbi,
> summary) (or wherever the generic for summary that you are trying to use
> is created).

Martin, thanks, this solved the problem.

But isn't this a bit weird? Suppose I am the author of package 'B' and
want to use the classes defined in package 'A'. I don't care about
exact details of the implementation of these classes, I don't want to
know that they are based on something in package 'C' (AnnotationDbi,
really). But I still have to import specific functions from 'C'.

Moreover, suppose the author of 'C' changes 'summary', e.g. puts it
into another package, 'D' and makes 'C' importing it from 'D'. This
will break my package, 'B' as well.

Anyway, thanks a lot for your help, Best Regards,
Gabor

> Martin
>


-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Why S4 method is not visible from another package?

2009-09-17 Thread Gábor Csárdi
Dear All,

maybe this is something obvious, I seem to be incapable of
understanding how S4 works.

So, in package 'A' I defined a "summary" method for my class:

setMethod("summary", signature(object="ListHyperGResult"),
  function(object, pvalue=pvalueCutoff(object), categorySize=NULL) {
 "whatever"
  })

"ListHyperGResult" has a subclass, "GOListHyperGResult":

setClass("GOListHyperGResult",
 representation=representation(conditional="logical"),
 contains="ListHyperGResult",
 prototype=prototype(testname="GO"))

The summary method is exported in the NAMESPACE:

exportMethods("summary")

Package 'B' depends on package 'A', this is stated in the
'DESCRIPTION' file. If I call 'summary' on a 'GOListHyperGResult' in
package B, then the default summary method is called instead of the
correct one, despite that I have

Browse[1]> showMethods("summary")
Function: summary (package base)
object="AnnDbBimap"
object="ANY"
object="Bimap"
object="DBIObject"
object="HyperGResultBase"
object="KEGGHyperGResult"
object="LinearMResultBase"
object="ListHyperGResult"
object="PFAMHyperGResult"
object="SQLiteConnection"
object="SQLiteDriver"
object="SQLiteResult"

Browse[1]> class(gos[[1]])
[1] "GOListHyperGResult"

But I still get:

Browse[1]> is(gos[[1]], "ListHyperGResult")
[1] TRUE
Browse[1]> summary(gos[[1]])
Length  Class   Mode
 1 GOListHyperGResult S4

What am I doing wrong?

> sessionInfo()
R version 2.9.0 (2009-04-17)
x86_64-redhat-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
 [1] hgu95av2.db_2.2.12  ALL_1.4.4   ExpressionView_0.1
 [4] caTools_1.9 bitops_1.0-4.1  KEGG.db_2.2.5
 [7] GO.db_2.2.5 RSQLite_0.7-1   DBI_0.2-4
[10] eisa_0.1genefilter_1.24.2   Category_2.10.0
[13] AnnotationDbi_1.6.0 Biobase_2.4.1   isa2_0.1

loaded via a namespace (and not attached):
[1] annotate_1.22.0 graph_1.22.2GSEABase_1.6.0  RBGL_1.20.0
[5] splines_2.9.0   survival_2.35-4 tools_2.9.0 XML_2.6-0
[9] xtable_1.5-5
>

Thanks,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Point patterns and igraph

2009-09-07 Thread Gábor Csárdi
Juanita,

On Tue, Sep 8, 2009 at 8:02 AM, juanita choo wrote:
> Hi,
>
> I have a data set consisting of the x and y coordinate locations of 1600
> points. I would like to generate a graph using the functions in igraph.
> However the graph making functions in igraph requires the data to be in the
> form of an adjacency matrix.

well, this is not quite true, there are quite a number of formats
igraph can create graphs from, see graph.adjlist(), graph.formula(),
graph.data.frame() or graph(). But you are right that
graph.adjacency() is probably the easiest for you.

> I'd like some advice on how to convert my point
> pattern to an adjacency matrix or functions out there that would do it
> directly. I've only gotten as far as obtaining the distance matrix using
> dist().

You are almost there, then. You can filter your distance matrix if you
like, and then create a weighted graph from the remaining edges:

co <- cbind(rnorm(10), rnorm(10))
D <- as.matrix(dist(co))
D[ D > 2 ] <- 0
G <- graph.adjacency(D, mode="undirected", weighted=TRUE)

Gabor

> Thanks for the help.
>
> Best,
> Juanita
>
> --
> Juanita Choo
> Graduate Student
> Section of Integrative Biology
> University of Texas at Austin
> 1 University Station Stop
> TX 78712
> +1 512 471 5773
>
>
>
> --
> Juanita Choo
> Graduate Student
> Section of Integrative Biology
> University of Texas at Austin
> 1 University Station Stop
> TX 78712
> +1 512 471 5773
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running R on read-only file system, without temporary directory

2009-09-04 Thread Gábor Csárdi
Thanks for all the answers. I have made some quick and dirty
modifications to make it start without a temporary directory and so
far it runs OK.

Obviously, I cannot do help(), example(), install.packages() and
Rprof() and maybe many more, but this is not an interactive machine,
but an Rserve server, so these are OK.

I will check the tempfile() and tempdir() calls to see what to expect.

Gabor

On Sat, Sep 5, 2009 at 2:40 AM, William Dunlap wrote:
>> -Original Message-
>> From: r-help-boun...@r-project.org
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Murdoch
>> Sent: Friday, September 04, 2009 5:05 PM
>> To: Gábor Csárdi
>> Cc: R mailing list
>> Subject: Re: [R] Running R on read-only file system,without
>> temporary directory
>>
>> On 04/09/2009 3:42 PM, Gábor Csárdi wrote:
>> > Dear All,
>> >
>> > I would like to do run R without having write permissions to any
>> > directory on the system. It seems that I need to modify the R source
>> > code for this, to make R start without creating a temporary
>> directory.
>> >
>> > So far, so good. But should I expect any more complications? Does R
>> > really need the temporary directory that much?
>>
>> Many R functions create temporary files in it.  (There are around 20
>> calls to tempfile() and another 20 to tempdir() in the base R
>> sources,
>> if my quick grep was right.  I've no idea how many calls
>> there are from
>> contributed packages.)  Would R work if these all failed?  I
>> don't know,
>> but I'd guess it wouldn't work very well.
>>
>> Duncan Murdoch
>
> On Linux R can do quite a bit without using R_SESSION_TMPDIR
> (which is where its temp files get made).  You can see if it can
> do enough for your needs by doing
>   Sys.chmod(Sys.getenv("R_SESSION_TMPDIR"), "")
> right after starting up.  E.g.,
>
>   > Sys.chmod(Sys.getenv("R_SESSION_TMPDIR"), "")
>   > 1:10
>    [1]  1  2  3  4  5  6  7  8  9 10
>   > names(cars)
>   [1] "speed" "dist"
>   > lm(dist~speed, data=cars)
>
>  Call:
>  lm(formula = dist ~ speed, data = cars)
>
>  Coefficients:
>  (Intercept)        speed
>      -17.579        3.932
>
>  > plot(.Last.value)
>  Hit  to see next plot:
>  Hit  to see next plot:
>  Hit  to see next plot:
>  Hit  to see next plot:
>  > help(plot)
>  Error in file(out, "wt") : cannot open the connection
>  In addition: Warning message:
>  In file(out, "wt") :
>    cannot open file '/tmp/RtmpPxKrY4/Rtxt327b23c6': Permission denied
>  > example(lm)
>  Error in file(out, "wt") : cannot open the connection
>  In addition: Warning message:
>  In file(out, "wt") :
>    cannot open file '/tmp/RtmpPxKrY4/Rex643c9869': Permission denied
>  > install.packages("ggplot2")
>  --- Please select a CRAN mirror for use in this session ---
>  Loading Tcl/Tk interface ... done
>  Error in install.packages("ggplot2") :
>    unable to create temporary directory '/tmp/RtmpPxKrY4/downloaded_packages'
>  In addition: Warning message:
>  In dir.create(tmpd) :
>    cannot create dir '/tmp/RtmpPxKrY4/downloaded_packages', reason 
> 'Permission denied'
>
> Of couse, that doesn't catch things done during startup or temp files
> created outside of the R-standard directory.
>
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com
>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Running R on read-only file system, without temporary directory

2009-09-04 Thread Gábor Csárdi
Dear All,

I would like to do run R without having write permissions to any
directory on the system. It seems that I need to modify the R source
code for this, to make R start without creating a temporary directory.

So far, so good. But should I expect any more complications? Does R
really need the temporary directory that much?

Thanks,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting to stdout

2009-08-28 Thread Gábor Csárdi
On Fri, Aug 28, 2009 at 1:33 PM, Gabor
Grothendieck wrote:
[...]
>
> I could have used this functionality in a previous project as well; however,
> for Oliver's application just pass the filename to the python program use that
> in the  tag (or have the python program pass the filename to
> the R program).
>
> If there is some aspect of this problem that has not been explained that
> truly does make passing the graphic file contents to the python
> program desirable
> then have R write out the graphic file and then have R read it back in.
>

Unfortunately, this is not always a good solution. For example, I am
running Rserve with connections from untrusted users. The Rserve
process is not allowed to write to the disk at all, but then there is
no easy way to create plots.

The patch Romain mentioned above looks like a good solution.

Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting to stdout

2009-08-28 Thread Gábor Csárdi
On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandel wrote:
[...]
> The goal was to produce a picture in a web-environment.
>
> At the moment rpy2 will be used maybe there are way to achieve something
> like that in this way, but I'm also new to rpy2.
>
> When the graphic could be written to stdout, the calling environment could 
> reead
> it from the forked process.
>
> But maybe rpy2 works different.
>
> Any ideas on that on-the-fly creation of pictures?
> If there would be no temporary files this would be fine.
> That's the reason why I looked for stdout as output channel.

Oliver,

I have a similar problem and had a similar question on the list about
a week ago all I could find out that some devices of the Cairo
package are supposed to support plotting to R connections (including
stdout), but it does not work in practice:

> library(Cairo)
> tc <- textConnection("foo", "w")
> CairoPNG(file=tc)
Error in Cairo(width, height, type = "png", file = filename, pointsize
= pointsize,  :
 file must be a filename. to support writing to a connection,
recompile R and Cairo with the R Connection Patch.

Information on the "R connection Patch" is welcome. Recompiling R and
Cairo is not a problem for me, I am putting together a special
environment anyway.

Best,
Gabor

[...]

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting to a connection

2009-08-25 Thread Gábor Csárdi
Dear All,

is there a way to plot to a connection? I mean, I would like to do
something like

> tc <- textConnection("foo", "w")
> png(tc)
> plot(...)
> close(tc)

According to the documentation of the Cairo package, this should work
with CairoPNG() (among others), but all I get is

> tc <- textConnection("foo", "w")
> CairoPNG(file=tc)
Error in Cairo(width, height, type = "png", file = filename, pointsize
= pointsize,  :
  file must be a filename. to support writing to a connection,
recompile R and Cairo with the R Connection Patch.

Anybody knows what is the "R Connection Patch"?

Btw. is there any particular reason that the png(), jpeg(), etc.
devices do not work with connections?

Thanks,
Gabor

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] FYI conflict between statnet, igraph

2009-08-18 Thread Gábor Csárdi
Ben,

I believe that the reason for this is that both packages define
functions with the same name and the 'network' package does not have a
NAMESPACE.

A possible workaround is to load the 'igraph' package first, and then
'statnet' (which loads 'network', etc.) next. At least

library(igraph)
library(statnet)
example(network)

works fine. Best,
Gabor

On Mon, Aug 17, 2009 at 9:12 PM, Ben
Mazzotta wrote:
> Dear R users:
>
> There appears to be a conflict between the statnet package and the
> igraph package.
>
> With igraph loaded into memory, the network() function of statnet
> failed, returning the error to the effect that the matrix being
> converted was "not a graph object." Removing igraph from memory restored
> statnet to proper function.
>
> Apologies if this is redundant. I could not find this documented in the
> help archives or in the docs for either package.
>
> Best,
>
> --
> Ben Mazzotta
> PhD Candidate
> Fletcher School, Tufts University
> 160 Packard Ave, Medford MA 02155
> benjamin.mazzo...@tufts.edu
> +1.617.462.4486
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simulation

2009-05-13 Thread Gábor Csárdi
On Wed, May 13, 2009 at 5:13 PM, Debbie Zhang  wrote:
>
>
> Dear R users,
>
> Can anyone please tell me how to generate a large number of samples in R, 
> given certain distribution and size.
>
> For example, if I want to generate 1000 samples of size n=100, with a N(0,1) 
> distribution, how should I proceed?
>
> (Since I dont want to do "rnorm(100,0,1)" in R for 1000 times)

Why not? It took 0.05 seconds on my 5 years old laptop.

Gabor

>
>
> Thanks for help
>
>
>
> Debbie
>
> _
> Looking to change your car this year? Find car news, reviews and more
>
> e%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641&_t=762955845&_r=tig_OCT07&_m=EXT
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] I'm offering $300 for someone who know R-programming to do the assignments for me.

2009-05-09 Thread Gábor Csárdi
That's typical, my profs used to do this to me all the time.

G.

On Sat, May 9, 2009 at 6:17 PM, Carl Witthoft  wrote:
> Sorry, but your professor offered me $500 NOT to do your assignments.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Hierarchical Diagram of Networks in sna or otherwise?

2009-05-05 Thread Gábor Csárdi
On Mon, May 4, 2009 at 8:31 PM, jebyrnes  wrote:
>
> Nearly.  The algorithm turns up slightly different graphs each time (and
> set.seed doesn't seem to make it consistent)

Hmmm, that should not happen, I'll check it out.

> and periodically chokes.

Can you send me the graph for which this happens?

> But
> better than what I had.  Hrm.  I don't know much about the algorithm
> graphviz uses for dot.  Do you have a reference on hand?

No, I don't. Have you checked the graphviz homepage?

> If it's simple,
> I'd be willing to take a whack at it.

I doubt that it is simple, but I think it would be very useful to have
a free implementation. (I would have already ported the graphviz
layout algorithms to igraph, but their licenses are not compatible.)

Best,
Gabor

>
> Gábor Csárdi-2 wrote:
>>
>> Jarrett,
>>
>> the 'igraph' package has a layout called layout.reingold.tilford that
>> is designed for trees, there is a slight chance that it is good enough
>> for you.
>>
>> Best,
>> Gabor
>>
>> On Wed, Apr 29, 2009 at 10:11 PM, jebyrnes  wrote:
>>>
>>> I've been using sna to work with some networks, and am trying to
>>> visualize
>>> them easily.  My networks are hierarchical (food webs).  All of the
>>> layout
>>> engines I've tried with gplot don't seem to plot hierarchical networks,
>>> as
>>> one would using dot from graphviz.  While I could do all of this by
>>> outputting to dotfiles and running it through graphviz, the graphics I
>>> get
>>> from R are much cleaner, and more easily integrated into my analyses.
>>>
>>> Is there any good way to diagram a hierarchical network in R, either with
>>> the sna library or otherwise?  It strikes me that at least the Netindices
>>> package can calculate trophic levels.  Could this be used for node
>>> placement?
>>>
>>>
>>> -Jarrett
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Hierarchical-Diagram-of-Networks-in-sna-or-otherwise--tp23301819p23301819.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Gabor Csardi      UNIL DGM
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Hierarchical-Diagram-of-Networks-in-sna-or-otherwise--tp23301819p23374024.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating datasets in packages

2009-04-30 Thread Gábor Csárdi
On Thu, Apr 30, 2009 at 10:33 PM, Hutchinson,David [PYR]
 wrote:
> In developing the package, I have associated datasets (*.rda) stored in the 
> data sub-directory. I built and installed the package successfully.
>
> When I load the BowRiver dataset and USArrests
>
>> data(BowRiver)
>> data(USArrests)
>> ls()
> [1] "data"      "USArrests"
>
> Why is mine stored as "data" and not "BowRiver"?

Because you have named it 'data' when you saved it into the .rda file,
haven't you?

Gabor

> -Original Message-
> From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
> Sent: Thursday, April 30, 2009 1:18 PM
> To: Hutchinson,David [PYR]
> Cc: r-help@r-project.org
> Subject: Re: [R] Creating datasets in packages
>
> The key question:
>>
>> What am I doing wrong?
>
> We don't know what you _did_. How did you save the data?
> Did you follow the directions in the Writing R Extensions manual? Does ls() 
> show the dataset? etc.
>
> You can "access the dataset from data" - do you mean that you can load the 
> data directly from the data directory within your package? How?
>
> Sarah
>
> On Thu, Apr 30, 2009 at 4:03 PM, Hutchinson,David [PYR] 
>  wrote:
>> I am developing an R package which includes datasets. The build and
>> install works correctly. However, when I access the dataset
>> ("BowRiver"), I get:
>>
>>> data(BowRiver)
>>> BowRiver
>> Error: object "BowRiver" not found. However, I can access the dataset
>> from
>>> data
>>
>> Example R datasets (such as USArrests) are loaded and can be accessed
>> by the dataset name:
>>
>>> data(USArrests)
>>> USArrests
>>               Murder Assault UrbanPop Rape Alabama          13.2
>> 236       58 21.2 Alaska           10.0     263       48 44.5 Arizona
>> 8.1     294       80 31.0 Arkansas          8.8     190       50 19.5
>> California        9.0     276       91 40.6 ...
>>
>> What am I doing wrong?
>>
>> Thanks in advance,
>> Dave
>>
>>
>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Curved arrows

2009-04-30 Thread Gábor Csárdi
On Thu, Apr 30, 2009 at 2:37 PM,   wrote:
> Hey - I tried this without success.  The igraph doesn't work with R 2.9.0,

That is strange, why not?

> so I'm using it with the 2.8.0 version which is the previous one I had.  Can 
> you write a simple code that would put an arrow with a curved shaft on, e.g
> plot(3,5)
> igraph.Arrows(3,4,4,5)

Exactly like this, but the function is not exported, and you need the
'curved' argument:

plot(3,5)
igraph:::igraph.Arrows(3,4,4,5)
igraph:::igraph.Arrows(3,4,4,5, curved=TRUE)
igraph:::igraph.Arrows(3,4,4,5, curved=-0.5)
igraph:::igraph.Arrows(3,4,4,5, curved=-1)
igraph:::igraph.Arrows(3,4,4,5, curved=1)

You need igraph version 0.5.2 for this I think. Type
head(igraph:::igraph.Arrows)
to see the other arguments to play with.

Gabor

> Thanks for your quick reply before that was much appreciated,
>
> Paul
>
> Gábor Csárdi-2 wrote:
>>
>> Paul,
>>
>> there might be other solutions as well, but there is an internal
>> function in the igraph package that can draw curved arrows, it is
>> called igraph:::igraph.Arrows(). As it is an internal function, it is
>> not documented, but I think it is pretty straightforward to use. For
>> the 'curved' argument you can give a number, try values between 0 and
>> 1, or (if I remember well)  -1 and 0 if you want it to curve towards
>> the opposite side.
>>
>> Best,
>> Gabor
>>
>> On Thu, Apr 30, 2009 at 10:57 AM, Paul Chatfield
>>  wrote:
>>>
>>> I'm trying to draw an arrow with a curved shaft on the graph as a
>>> straight
>>> one looks messy on a detailed graph.  I've looked in arrows but it
>>> doesn't
>>> seem to give an option.  larrows doesn't look much more promising.  I had
>>> a
>>> look in the archive and couldn't find anything.  Any thoughts?
>>>
>>> Thanks
>>>
>>> Paul
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Curved-arrows-tp23312316p23312316.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Gabor Csardi      UNIL DGM
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> Quoted from:  http://www.nabble.com/Curved-arrows-tp23312316p23312605.html
>
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Curved arrows

2009-04-30 Thread Gábor Csárdi
Paul,

there might be other solutions as well, but there is an internal
function in the igraph package that can draw curved arrows, it is
called igraph:::igraph.Arrows(). As it is an internal function, it is
not documented, but I think it is pretty straightforward to use. For
the 'curved' argument you can give a number, try values between 0 and
1, or (if I remember well)  -1 and 0 if you want it to curve towards
the opposite side.

Best,
Gabor

On Thu, Apr 30, 2009 at 10:57 AM, Paul Chatfield
 wrote:
>
> I'm trying to draw an arrow with a curved shaft on the graph as a straight
> one looks messy on a detailed graph.  I've looked in arrows but it doesn't
> seem to give an option.  larrows doesn't look much more promising.  I had a
> look in the archive and couldn't find anything.  Any thoughts?
>
> Thanks
>
> Paul
> --
> View this message in context: 
> http://www.nabble.com/Curved-arrows-tp23312316p23312316.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Hierarchical Diagram of Networks in sna or otherwise?

2009-04-29 Thread Gábor Csárdi
Jarrett,

the 'igraph' package has a layout called layout.reingold.tilford that
is designed for trees, there is a slight chance that it is good enough
for you.

Best,
Gabor

On Wed, Apr 29, 2009 at 10:11 PM, jebyrnes  wrote:
>
> I've been using sna to work with some networks, and am trying to visualize
> them easily.  My networks are hierarchical (food webs).  All of the layout
> engines I've tried with gplot don't seem to plot hierarchical networks, as
> one would using dot from graphviz.  While I could do all of this by
> outputting to dotfiles and running it through graphviz, the graphics I get
> from R are much cleaner, and more easily integrated into my analyses.
>
> Is there any good way to diagram a hierarchical network in R, either with
> the sna library or otherwise?  It strikes me that at least the Netindices
> package can calculate trophic levels.  Could this be used for node
> placement?
>
>
> -Jarrett
> --
> View this message in context: 
> http://www.nabble.com/Hierarchical-Diagram-of-Networks-in-sna-or-otherwise--tp23301819p23301819.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] covariance

2009-04-19 Thread Gábor Csárdi
sapply(seq_len(nrow(x)), function(i) var(x[i,], y[i,]))

Gabor

On Sun, Apr 19, 2009 at 7:12 PM, Benny Chain  wrote:
> Does anyone know a way to calculate the covariances between two
> arrays/matrices x and y, row by row. i.e. var(x[n,],y[n,]) for all n ?
>
> Benjamin Chain
> Division of Infection and Immunity
> Windeyer Building
> UCL, 46 Cleveland St.
> London W1T 4JF
> Fax 00 44 20 7679 9301
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] [R-pkgs] igraph 0.5.2

2009-04-18 Thread Gábor Csárdi
igraph is a package for graphs/networks. It has a C core and
uses a simple and fast graph representation allowing millions
of vertices and edges.

LINKS

Release notes for the 0.5.2 version:
http://igraph.sourceforge.net/relnotes-0.5.2.html

Release notes for the 0.5.1 version:
http://igraph.sourceforge.net/relnotes-0.5.1.html

Complete list of changes:
http://igraph.sourceforge.net/news.html

The igraph homepage: http://igraph.sf.net

Since there was no announcement about igraph version 0.5.1
on R-pkgs, here is a list of the more important new things of both
version 0.5.2 and 0.5.1.

NEW FEATURES IN THE 0.5.2 VERSION

- We have some support for bipartite (two-mode) graphs now.
  See ?graph.incidence, ?get.incidence for dealing with
  incidence matrices, ?graph.bipartite for a way to
  create bipartite graphs, ?bipartite.projection for
  creating one-mode projections. See ?is.bipartite for
  deciding whether a graph has a bipartite structure.
- A new simple and fast community finding algorithm called 'label
  propagation' was added, see ?label.propagation.community
  for details.
- The DrL layout generator now supports 3d layouts.
- A limited Tcl/Tk igraph GUI was added, please note that it supports
  only a small fraction of the igraph functions. You can start it with
  the tkigraph() function.
- Johnson's algorithm is now supported by the shortest path finder.
  It allows negative edge weight, but not negative cycles.
  See ?shortest.paths.
- The graph.knn function was added to calculate the average
  nearest neighbor degree. It supports edge weights as well.
- Curved edges are now supported by plot() and tkplot(), see
  ?igraph.plotting for the details.
- Many bugs and memory leaks were fixed, see the News section on the
  igraph homepage for details.

NEW FEATURES IN THE 0.5.1 VERSION

- DrL layout generator was added, see ?layout.drl.
- Uniform sampling of graphs with a given degree sequence,
  see ?degree.sequence.game.
- Conversion functions to/from graphNEL objects (graph package),
  see ?igraph.to.graphNEL and ?igraph.from.graphNEL.
- Conversion functions to/from sparse matrices (Matrix package),
  see ?graph.adjacency and the 'sparse' argument of
  ?get.adjacency.
- Creating graphs from adjacency lists, see ?graph.adjlist.
- The function graph.data.frame has an argument called
  'vertices' and this makes it very easy to create graphs
  with a lot of vertex and edge metadata.
- The Dijkstra and Bellman-Ford shortest path algorithms
  were added, see ?shortest.paths.
- The function is.mutual() was added, this tests edge reciprocity.
- The plot() function now supports plottings different vertex
  shapes. See ?igraph.plotting and ?igraph.vertex.shapes for
  detaills.
- Many bugs were fixed, see the News section on the igraph
  homepage for details.

PACKAGE DESCRIPTION:

igraph is originally a C library for graphs, but has interfaces
to high level languages like R, Python and Ruby. The R package
contains BOTH the C library and its R interface.

igraph supports:

- graph generators, creating both regular structures like trees,
  lattices, etc. and various random graphs.
- a rich set of functions calculating structural properties of
  graphs, like vertex centrality (degree, betweenness, closeness,
  page rank, eigenvector centrality, Burt's constraints, etc.),
  shortest paths, dyad and triad census, network motifs, girth,
  K-core decomposition, etc.
- attributes can be associated with the vertices/edges of the graph,
  or the graph itself. The attributes can be arbitrary R objects.
- graph visualization using regular R devices, interactive visualization
  using Tcl/Tk, 3D visualization using RGL.
- graph layout generators, the standard Kamada-Kawai and
  Fruchterman-Reingold algorithms are included, plus many more.
- Functions for graph and subgraph isomorphism, the BLISS and the VF2
  algorithms are included.
- Functions for maximal network flows, minimal cuts, vertex and
  edge connectivity.
- igraph can read and write many popular file formats used for
  storing graph data: GraphML, Pajek, GML and others.
- igraph contains implementations of many community structure
  detection algorithms proposed recently.

-- 
Gabor Csardi  UNIL DGM

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Igraph: family 'serif' not included in PostScript device

2009-04-16 Thread Gábor Csárdi
Knut, see this thread here:
http://lists.gnu.org/archive/html/igraph-help/2007-07/msg00010.html

Best,
Gabor

On Thu, Apr 16, 2009 at 10:03 AM, Knut Krueger  wrote:
> Does anybody know how to solve this error?
>
> postscript(file= "file.ps", family = "Helvetica", font = "Helvetica")
> plot.igraph(g, layout=layout.circle, vertex.label.font=2)
> dev.off()
> error in  text.default(x, y, labels = labels, col = label.color, family =
> label.family,  :
>  family 'serif' not included in PostScript device
>
>
> Regards Knut
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Search for a graph package - see link

2009-04-15 Thread Gábor Csárdi
Knut, I think you have an older version of igraph that does not
support curved edges. Again, please read
http://lists.gnu.org/archive/html/igraph-help/2009-04/msg00104.html
and install version 0.5.2, it is on CRAN now (except for OSX).

Gabor

On Wed, Apr 15, 2009 at 11:30 AM, Knut Krueger  wrote:
> Gábor Csárdi schrieb:
>>
>>
>
> Dear Gabor, I am very sorry but i am not able to reproduce your example.
> there is no change, i am using r 2.8.0
[...]

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Search for a graph package - see link

2009-04-15 Thread Gábor Csárdi
On Wed, Apr 15, 2009 at 9:35 AM, Knut Krueger  wrote:
> Gábor Csárdi schrieb:
>>
>>> The would prefer two parallel arrows one for each direction.
>>>
>>
>> You can set 'curved' to a value close to zero and then the arrows will
>> be only a bit curved.
>>
>>
>
> No I am lost ... do you mean?
> ...
> E(g)$curved <- 0.5
> ...
> plot.igraph(g, layout=layout.kamada.kawai, vertex.label.font=2)
> I do not see any change ..

Because 0.5 the default value. Try 0.1. I.e.

library(igraph)
g <- graph.ring(3, dir=TRUE, mut=TRUE)
g$layout <- layout.circle

E(g)$curved <- 0.5
plot(g)

E(g)$curved <- 0.1
plot(g)

> and I do not found any curved assignment in the plot.igraph function.

It is a good idea to read the documentation as well, especially if you
don't understand the code. See ?igraph.plotting and search for
'curved'.

[...]
> http://www.equine-science.de/temp/r-graph.jpg
[...]

That possible with igraph, you need to define a new vertex shape for
it. See ?igraph.vertex.shapes and the R/plot.shapes.R file for some
simple example shapes.

Or you can write the whole thing for yourself, using 'segments', etc.

G.

> Regards Knut
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Search for a graph package - see link

2009-04-14 Thread Gábor Csárdi
On Tue, Apr 14, 2009 at 6:46 PM, Knut Krueger  wrote:
[...]
> In that case all lines would be thick and the actions Node 1 -> 2  ,Node 3
> -> 1,Node 2 -> 3   would be invisible, so I tried the narrow arrows to get
> above the thick arrows in an other colour, but I found no rule to order them
> that the are always on the top ... and the team was not satisfied with this
> suggestion ;-)

Then make the arrows narrower. Or assign the arrow width
logarithmically to you edge weight. I.e. something like

E(g)$width <- log(E(g)$weight)+1

> The would prefer two parallel arrows one for each direction.

You can set 'curved' to a value close to zero and then the arrows will
be only a bit curved.

> Its a very
>  long mathematical formula to display those arrows, depending on the radius
> of the circles, and there is a ...hidden...error in the formula.

I am a bit lost. What formula are we talking about?

> So I tried to ask again if there is another solution.
>
> By the way: Do you know such arrow funtion: arrow(starting_point, angle,
> length) ?

I know igraph:::igraph.Arrows, there might be others as well,
G.

[...]

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Search for a graph package - see link

2009-04-14 Thread Gábor Csárdi
On Tue, Apr 14, 2009 at 6:07 PM, Knut Krueger  wrote:
> Gábor Csárdi schrieb:
>>
>> Hmmm, how should 'plot' know automatically what size/width you want?
>> Sorry, I don't really know what you want to achieve here. If you want
>> to calculate the width from some properties of the graph, then simply
>> do that and assign it as the 'width' argument.
>>
>>
>
> Hi Gábor,
> the radius of the circle is representing the numbers of "actions" of the
> node to all other nodes.
> I need an additionally information about the numbers of actions *between*
> the nodes differentiated by the direction from and to the nodes.
>
> Example
> Node 1 -> 2      1 actions
> Node 2 -> 1    25 actions
> Node 3 -> 1     4 actions
> Node 1 -> 3   10 actions
> Node 2 -> 3     5 actions
> Node 3 -> 2     2 actions
>
> I am looking for any graph which shows the direction and counts of the
> actions with f.e different thickness of the arrows,
> It must be  viewable
> <http://dict.leo.org/ende?lp=ende&p=thMx..&search=viewable> that the actions
> from Node 2 to Node 1 are much more than from Node 1 to 2 and also more then
> from node 3 to three, and so on.
>
> Maximum nodes: about 20

Follow along these lines:
http://lists.gnu.org/archive/html/igraph-help/2009-04/msg00104.html
plus set the 'width' edge attribute to represent the number of actions.

Best,
Gabor

> Regards Knut
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum Spanning Tree

2009-04-08 Thread Gábor Csárdi
On Wed, Apr 8, 2009 at 10:20 PM, jpearl01  wrote:
>
> That's like a miracle!  The only thing that would make this graph perfect is
> if the lengths of the edges were in the same ratio as the actual edge
> lengths from the matrix.  Is it possible to alter that?

Not really. The thing is that the nodes are ordered into layers based
on the distance (in steps) from the root. This is how the
Reingold-Tilford layouting algorithm works. If you start changing the
lengths of the edges, then the nodes could move on top of each other.

You would need to modify the algorithm itself for this, I don't know
how difficult that would be.

What you can do is modifying the width of the edges, I know that is
not as good, but it is still something:

library(igraph)

tab <- read.csv("http://www.nabble.com/file/p22957493/sp_matrix.csv";)
tab <- tab[,-1]

g <- graph.adjacency(as.matrix(tab), weighted=TRUE)
V(g)$label <- V(g)$name

mst <- minimum.spanning.tree(g)

rescale <- function(x,from,to) {# linearly rescale a vector
  r <- range(x)
  (x-r[1]) / (r[2]-r[1]) * (to-from) + from
}

E(mst)$width <- rescale(E(mst)$weight,1,5)   # width between 1 and 5

lay <- layout.reingold.tilford(mst, root=which.max(degree(mst))-1)
lay <- cbind(lay[,2], lay[,1])# rotate
x11(width=15, height=8)
plot(mst, layout=lay, vertex.size=25, vertex.size2=10,
 vertex.shape="crectangle", asp=FALSE,
 vertex.label.cex=0.7, vertex.color="white", edge.arrow.mode=0)

G.

> Thank you!!
> ~josh
>
[...]

-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum Spanning Tree

2009-04-08 Thread Gábor Csárdi
Actually,

library(igraph)

tab <- read.csv("http://www.nabble.com/file/p22957493/sp_matrix.csv";)
tab <- tab[,-1]

g <- graph.adjacency(as.matrix(tab), weighted=TRUE)
V(g)$label <- V(g)$name

mst <- as.undirected(minimum.spanning.tree(g))

lay <- layout.reingold.tilford(mst, root=which.max(degree(mst))-1)
lay <- cbind(lay[,2], lay[,1])# rotate
x11(width=15, height=8)
plot(mst, layout=lay, vertex.size=25, vertex.size2=10,
 vertex.shape="rectangle", asp=FALSE,
 vertex.label.cex=0.7, vertex.color="white")

works relatively well for me on your graph. It doesn't for you?

Best,
Gabor

On Wed, Apr 8, 2009 at 9:14 PM, jpearl01  wrote:
>
>
> Make the graph undirected first and then choose the right plotting
> parameters. E.g. the following works fine for me:
>
> set.seed(2)
> g <- erdos.renyi.game(100, 300, type="gnm", directed=TRUE)
> E(g)$weight <- runif(ecount(g))
> mst <- minimum.spanning.tree(g)
>
> mst <- simplify(as.undirected(mst))
> lay <- layout.reingold.tilford(mst, root=which.max(degree(mst))-1)
> plot(mst, layout=lay, vertex.size=5, asp=FALSE, vertex.color=NA,
>       vertex.frame.color=NA)
>
> G.
>
>
> Thanks for all your help Gabor,  However, I'm unable to get a display in R
> which is at all readable.  I'm not sure why that is (if the data is
> generated randomly, like in your example the tree builds/reads fine...
> however on my dataset whichever node is picked as the root just completely
> over powers the rest of the nodes which all clump together in a manner that
> is unreadable).  My dataset is:
> http://www.nabble.com/file/p22957493/sp_matrix.csv sp_matrix.csv
> If you would like to take a look.  However, as it stands I think I'll have
> to find another option.  Thanks again for all your efforts.
>
> ~josh
> --
> View this message in context: 
> http://www.nabble.com/Minimum-Spanning-Tree-tp22934813p22957493.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum Spanning Tree

2009-04-08 Thread Gábor Csárdi
On Wed, Apr 8, 2009 at 6:12 PM, jpearl01  wrote:
>
>
>>I am not sure what you mean. Of course you can plot it using different
>>layouts, e.g. with layout.reingold.tilford (after choosing the root
>>vertex in some way) and then it looks like a usual tree plot, but why
>>would that be any better?
>
> I'd like to be able to distinguish between the nodes better.  For example
> the image that I get looks like:
> http://www.nabble.com/file/p22954099/mst.gif mst.gif
>
> The tree nodes are just too close together to be able to read.  I think the
> problem might be that some distances between the nodes are *much* smaller
> than other edges.    The graph does not need to be directed, since the
> distance metric does not imply a direction. The most important part is just
> being able to see and differentiate between the nodes, and right now they
> seem to be all lumped together.  How can I make it more readable?

Make the graph undirected first and then choose the right plotting
parameters. E.g. the following works fine for me:

set.seed(2)
g <- erdos.renyi.game(100, 300, type="gnm", directed=TRUE)
E(g)$weight <- runif(ecount(g))
mst <- minimum.spanning.tree(g)

mst <- simplify(as.undirected(mst))
lay <- layout.reingold.tilford(mst, root=which.max(degree(mst))-1)
plot(mst, layout=lay, vertex.size=5, asp=FALSE, vertex.color=NA,
   vertex.frame.color=NA)

G.

> Thanks,
> ~josh
>
>
> --
> View this message in context: 
> http://www.nabble.com/Minimum-Spanning-Tree-tp22934813p22954099.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Minimum Spanning Tree

2009-04-08 Thread Gábor Csárdi
On Tue, Apr 7, 2009 at 11:06 PM, jpearl01  wrote:
>
> There was an error in the file... an extraneous comma.  That's taken care of.
> however, my tree prints out an image that doesn't seem like a mst.  Attached
> is the csv file I used...

Well, it looks definitely a tree to me.

> http://www.nabble.com/file/p22938299/sp_matrix.csv sp_matrix.csv
>
> I'd like it to look something like the image file also attached...
> http://www.nabble.com/file/p22938299/2006-08-27_MST.png 2006-08-27_MST.png
>
> Is there a different layout that would accomplish that?  Or if not that
> exactly, one that would help make the results a little clearer?

I am not sure what you mean. Of course you can plot it using different
layouts, e.g. with layout.reingold.tilford (after choosing the root
vertex in some way) and then it looks like a usual tree plot, but why
would that be any better?

Unless there is some external information about the graph (e.g.
spatial positions of the nodes, or a distinguished root vertex), the
layout on the image is just as good as the others.

Gabor

> Thanks for all the help!
> ~josh
> --
> View this message in context: 
> http://www.nabble.com/Minimum-Spanning-Tree-tp22934813p22938299.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >