[R] Plotting horizontal dendrograms
Matthias Kohl
Matthias.Kohl at stamats.de
Mon Jun 2 19:08:07 CEST 2008
Dear Charles,
the sample code you cite has an additional "as.dendrogram" compared to
your code. Hence, dend1 is of class dendrogram (class(dend1)) and if you
call plot(dend1) the method for dendrograms (i.e., plot.dendrogram) is
executed which has a horiz argument; confer ?plot.dendrogram.
Whereas in your code h is of class hclust (class(hclust)) and therefore
plot(h) leads to a call of plot.hclust which has no horiz argument; cf.
?plot.hclust.
So, adding as.dendrogram in your code should remove the warning messages
and give what you want; e.g.
plot(as.dendrogram(h), horiz = TRUE)
Best,
Matthias
Charles K. Minns wrote:
> I am using hclust and plot to produce dendrograms. Using my input data I am
> able to complete an analysis and obtain a vertical plot.
> I want to be able to plot the dendrogram horizontally.I am using version 2.6
> of R and have updated my packages recently.
>
> Using the sample script for dendrograms I can produce a horizontal plot
> using the instruction horiz = TRUE in plot().
> When I use the same instruction in my own script I get a warning message
> that horiz, and horizontal, are not recognized commands in plot.
> I cannot find any documentation in R on how to change the orientation of
> plots and general searches for information on this subject.
> Can someone explain why my script does not work.
>
> Sample code follows:
> -----------------------------------------------------------------------
> # Sample code extracted from the Dendrogram documentation in R
> #
> require(graphics); require(utils)
>
> hc <- hclust(dist(USArrests), "ave")
> (dend1 <- as.dendrogram(hc)) # "print()" method
> str(dend1) # "str()" method
> str(dend1, max = 2) # only the first two sub-levels
>
> op <- par(mfrow= c(2,2), mar = c(5,2,1,4))
> plot(dend1, horiz = TRUE)
> plot(dend1)
> #
> # My code
> #
> x <- read.table("Rclust2.data",header=TRUE)
>
> m <- data.matrix(x)
> d <- as.dist(m)
> h <- hclust(d)
> plot(h, horiz = TRUE)
>
> ----------------------------------------------------------------------
> The three plot commands execute. Plot 1 is horizontal, plot 2 is vertical
> and plot 3 is vertical. Plus plot 3
> generates the console output:
> -----------------------------------------------------------------
>
>> #
>> # My code
>> #
>> x <- read.table("Rclust2.data",header=TRUE)
>>
>> m <- data.matrix(x)
>> d <- as.dist(m)
>> h <- hclust(d)
>> plot(h, horiz = TRUE)
>>
> Warning messages:
> 1: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
> 2: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
> 3: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
> "horiz" is not a graphical parameter
> ---------------------------------------------------------------
>
> I would appreciate help solving this problem. Doubtless there is a simple
> answer.
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
--
Dr. Matthias Kohl
www.stamats.de
More information about the R-help
mailing list