[R] Question about plot.mona {cluster}

Dennis Murphy djmuser at gmail.com
Sat Sep 10 00:47:14 CEST 2011


Hi:

Here are a couple of ways to do this. The barplot() attempt is pretty
close to the original banner plot except that the color is transparent
to the (white) background. The ggplot2 graph is similar, but the code
may be less familiar if you don't use the package. In the latter, the
variable names vector, step and variable need to be reversed because
ggplot2 only does vertical histograms and the result has to be
'flipped' to get a corresponding horizontal one.

# (1) barplot()
# vector of variable abbreviations
nms <- rownames(ma$data)[ma$order]

# Two things: (i) replace step 0 by 6;
#    (ii) change 'NULL' to NA
# create a data frame to use as a reference
cdat <- data.frame(val = (1:19) - 0.5,
                   step = replace(ma$step, which(ma$step == 0L), 6),
                   variable = replace(ma$variable, which(ma$variable
== 'NULL'), NA))
with(cdat, barplot(step, horiz = TRUE, xlab = 'Separation step',
                   col = 'transparent', space = 0))
axis(2, at = 0:19, labels = nms, las = 1)
with(cdat, text(x = step + 0.2, y = val, labels = variable, col = 'red'))

###################################
# (2) same thing in ggplot2

library('ggplot2')
nms2 <- rev(rownames(ma$data)[ma$order])
cdat2 <- data.frame(val = (1:19) - 0.5,
                   step = rev(replace(ma$step, which(ma$step == 0L), 6)),
                   variable = rev(replace(ma$variable,
which(ma$variable == 'NULL'), NA)))
ggplot(cdat2, aes(x = val, y = step)) +
    theme_bw() +
    geom_histogram(stat = 'identity', colour = 'grey60', fill = NA, size = 1) +
    geom_text(aes(y = step + 0.3, label = variable), colour = 'red') +
    ylim(0, 6) +
    labs(x = '', y = 'Separation step') +
    scale_x_continuous(breaks = 0:19, labels = nms2) +
    coord_flip() +
    opts(panel.grid.major = theme_blank(),
         panel.grid.minor = theme_blank())

HTH,
Dennis

On Fri, Sep 9, 2011 at 1:10 PM, trekvana <trekvana at aol.com> wrote:
> Hello all, I what to print the banner plot that is output from the mona
> method in the cluster package but the problem is I dont want to print all
> that red ink. Here is an example:
>
> data(animals)
> ma <- mona(animals)
> ma
> ## Plot similar to Figure 10 in Struyf et al (1996)
> plot(ma)
>
> I can change the bar color by using the argument col=c(0,0) -
> plot(ma,col=c(0,0)) - but then the variable labels also get colored white.
> Is there a way to remove the bar colors but leave the variables colored?
>
> Thank you
> George Skountrianos
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Question-about-plot-mona-cluster-tp3802672p3802672.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list