R Colored dendrogram suggestions? - r

I want to make colored dendrograms and have yet to find a sufficient library: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=79
This graphic/library looks promising but cannot install the A2E library?
Trying to install on windows, downloaded the tar.gz file and cannot install package from the R console.
In addition:
Warning messages:
1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
2: In gzfile(file, "r") :
cannot open compressed file 'A2R_0.0-4.tar.gz/DESCRIPTION', probable reason 'No such file or directory'
Can anyone see if they can get this A2R library working, confirm error, or suggest a good colored dendrogram library?

(It might help if you spelled it correctly.) A2R is a source package. So you might need to have the system toolchain for compilation. Those are typically in your system if you are on Linux, but not if you are on a Mac (as I am) or on Windows. The package does compile from source on a Mac. And the compilation process may not have needed the toolchain. So try this:
install.packages("<fullpath> A2R_0.0-4.tar.gz", type ="source")
There are a few other dependencies: 'trimcluster', 'prabclus' , 'MASS' , 'cluster', 'mclust', 'flexmix', 'modeltools', 'stats4', 'multcomp', 'mvtnorm'. I am able to get most of that graphic but the left side curve does not appear as shown and I did get an error:
Error in hubertgamma[i] <- cluster.stats(d.usa, cutree(h.usa, k = i + :
replacement has length zero:
If you do not want the heights of the dendrogram scaled to their depth you can add this modification to the hclust object:
h.usa$height <- log(h.usa$height)

You could use the dendrapply() function in R's built-in dendrogram code to apply custom leaf and node coloring. See the following mailing list thread for hints.

Related

Error when using read.gml or read.graph to read a GML file

I am trying to load a file from the spanish building census (any of the files there will serve as an example, I'm using the 03001-ADSUBIA buildings one).
I have tried the read.gml function from the Multiplex package and get the following error:
read.gml("A.ES.SDGC.BU.03001.building.gml")
Error in which(("node" == arx) == TRUE)[1]:which(("edge" == arx) == TRUE)[1] :
NA/NaN argument
Then I tried the read.graph from the igraph package and also got an error:
read.graph("A.ES.SDGC.BU.46900.building.gml", format=c("gml"))
Error in .Call("R_igraph_read_graph_gml", file, PACKAGE = "igraph") :
At foreign.c:1127 : Parse error in GML file, line 1 (syntax error, unexpected STRING, expecting $end), Parse error
What am I doing wrong, and what can I do to fix it?
igraph and multiplex do not work because that is a different GML: Graph Modelling Language, as the name suggests, is for graphs (or networks). Your GML is Geography Markup Language.
Found an alternative on this post. However I would like to know why specific packages like multiplex or igraph cannot get the job done properly...
Code:
llayer<-ogrListLayers("A.ES.SDGC.BU.03001.building.gml")[1]
a<- readOGR(dsn="A.ES.SDGC.BU.46900.building.gml", layer=llayer, encoding = "UTF-8")
I have successfully used GEPHI to open gml files, and then use GEPHI'S export function (menu driven) to create 'new' gml files that open with igraph in R.
Details about GEPHI and the gml file definition are here.

Error in file(con, "w") : cannot open the connection [Using R-Studio to plot interactive bar graphs using rCharts, knitr]

I am getting an error when I am trying to run the code below in R-Studio 3.3.2 on a Mac (OS Sierra)
devtools::install_github('ramnathv/rCharts')
install.packages("knitr")
require(rCharts)
require(knitr)
haireye <- as.data.frame(HairEyeColor)
n1 <- nPlot(Freq ~ Hair, group = 'Eye', type = 'multiBarChart',
data = subset(haireye, Sex == 'Male')
)
n1$save('fig/n1.html', cdn = TRUE)
cat('<iframe src="fig/n1.html" width= 100%, height=600</iframe>')
Pls see output below:
Error in file(con, "w") : cannot open the connection
In addition: Warning message: In file(con, "w") : cannot open file 'fig/n1.html': No such file or directory
But I am able to generate the reqd bar graph in the viewer when I use:
n1$show(cdn = TRUE)
in lieu of n1$save('fig/n1.html', cdn = TRUE)
To take care of write permission issues (if any), I also tried including the line below, altering the WD path wherever necessary.
knitr::knit2html('Users/documents/n1.html')
But it did not help. I see the n1.html file created but it only opens an empty browser.
Any help to resolve this is appreciated.
Best,
S
A lot of times we face this error due to caching in RStudio and in that case, actual code errors don't show up. Restart RStudio and this error will be gone and actual code errors would show.
You have two separate problems.
The connection error appears because the fig/ folder does not exist. Create the folder and the save command will work. R has functions to check the existance of directories and create new ones if you would like to do it in your code.
The second problem comes from the way you save, you should use n1$save('fig/n1.html', standalone = TRUE). Here you have a similar situation.
As a side-note, I would say rCharts is not currently developed or mantained at all, so I would recommend you to use another library for your charts. In my opinion Plotly is quite nice. rCharts brought the NVD3 project to R and the chart style is in my opinion really nice. However, as far as I know both projects are stopped so I would look for a library that is still alive.
I have fixed this problem with good old rm(list=ls()) . I know I have
fallen into sequences where the error stops execution of my script. I fix the error, and then it won't run. This is likely due to lazy evaluation but it is a near impossible problem to diagnose, so the solution at the top works almost all the time.

R package 'biomod2' cannot find file when executing plot function

I am attempting to use the plot() function in the biomod2 package, following a vignette here (http://finzi.psych.upenn.edu/usr/share/doc/library/biomod2/doc/Simple_species_modelling.pdf). Below is the error I am getting:
getwd()
# [1] "/home/gjanzen/Documents/Hufford/Drought/Data/Layers"
plot(myBiomodData)
Error in getExportedValue(pkg, name) : cannot open file
'~/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb': No
such file or directory In addition: Warning message: In
getExportedValue(pkg, name) : restarting interrupted promise
evaluation
I have confirmed that the Rdata.rdb exists, in the following directory:
f <- file.choose()
f
# [1] "/home/gjanzen/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb"
So, to me, it looks like the plot() function is looking in the wrong place. How can I change where this function looks for Rdata.rdb? Can I alter the path somehow? Or would changing my working directory fix this?
PS - This is my first post on Stack Overflow, so please forgive any mistakes in etiquette, and/or feel free to point them out to me so that I do not repeat them.
I think that the first thing to try is to reinstall the package viridisLite that seems to be the one that is causing troubles.
install.packages('viridisLite', dep = TRUE)
If this not solves the issue you should try to open a new plotting device threw x11() to check if the issue is not coming from the R (resp. RStudio) plotting device itself.

R {ape} clustal cannot find clustalw2

I am a beginner in R.
I would like to use R clustal function in package ape to process my DNA sequence, so I can us {pegas} to perform further analysis.
However, when I first try the example provided in the manual:
clustal(woodmouse, pw.gapopen = 1, pw.gapext = 1, exec = "clustalw2")
But I got an error message:
/bin/sh: clustalw2: command not found
Error in file(file, "r") : cannot open the connection. In addition: Warning massage: In file(file, "r") : cannot open file '/var/folders/vm/fzyykk3x21g55fdvpctj7s900000gn/T//Rtmp0RjsMr/input_clustal.aln' :No such file or directory
I would like to know how to fix this problem? By the way, the OS I use is Mac OS 10.9. Thank you.
Make sure that you have clustalw2 installed. Download *.msi from here:
http://www.clustal.org/download/current/
Then run
require(ape)
fix(clustal)
Make sure that the following part of the clustal function:
shortPathName("C:/Program Files/ClustalW2/clustalw2.exe")
...matches the placement of clustalw2.exe in your system perfectly. Also exhange all the "/" with "\".
Hope that works - worked for me...

In R, after installed a package,' pixmap', Error in file(file, open = "rb") : cannot open the connection

I'm learning R programming, using the book, "The Art of R Programming".
In chapter 3.2.3 Extended Example: Image Manipulation. The author Matloff tries to use a Mount Rushmore gray-scale image to illustrate that the image is stored in matrix. He used a library called pixmap. And I downloaded the package, installed it.
> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
> mtrush1
Pixmap image
Type : pixmapGrey
Size : 194x259
Resolution : 1x1
Bounding box : 0 0 259 194
> plot(mtrush1)
This is what the book has written, and I tried to run this, but got the error message,
> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
Error in file(file, open = "rb") : cannot open the connection
In addition: Warning message:
In file(file, open = "rb") :
cannot open file 'mtrush1.pgm': No such file or directory
starting httpd help server ... done
What does this mean? cannot open the connection? And also the mtrush1.pgm does not exist? How should I fix it here? Any help? Much appreciated.
Summary:
Add the argument cellres=1 to your function call and you should be fine.
Answer:
The second error you saw--Warning message: In rep(cellres, length = 2) : 'x' is NULL so the result will be NULL--is because you haven't set the cellres argument and, as a result, "cellres" assumes its default value (i.e. 'NULL'--hence the warning). For what you're working on, setting the cellres argument to 1 will do the trick (though you can pass in a two-element vector with unequal values and see just how it affects your figure by plotting the resulting object).
Note: Though it's a little late to be answering, I figure that since I had the same problem earlier today (and since Google was no help) a response was probably warranted.
This means that the file mtrush1.pgm is not in current directory. You should either setwd to the directory that contains this file, or specify the complete path in read.pnm.
For the file mtrush1.pgm, you can download it from http://heather.cs.ucdavis.edu/~matloff/
The file mtrush1.pgm and the R scripts from the book "The Art Of R Programming" can be found at this GitHub site.

Resources