[R] Plotting hclust() results

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Tue Aug 6 13:12:09 CEST 2019


Hello,

I don't know if you want something like this:

hc_long <- reshape::melt(hc, id.vars = "Cluster") # convert to long format

library(ggplot2)

ggplot(hc_long, aes(x = Cluster, y = value, colour = variable)) +
   geom_point() +
   geom_line() +
   coord_flip() +
   facet_wrap(~ variable)

#Data

hc <- read.table(text = "
   Cluster     A     B     C     D     E     F
                  1       1  0.67  0.56  0.54  0.03 -0.97 -1.09
                  2       2  0.52  0.43  0.51  0.05 -0.86 -0.96
                  3       3  0.2   0.3   0.19  0.08  0.02  0.09
                  4       4 -1.3  -1.13 -1.78 -0.05 -0.23 -0.23
                  5       5 -1.6  -1.3  -1.34 -0.23 -0.45 -0.45

", header = TRUE)


Hope this helps,

Rui Barradas

Às 03:25 de 06/08/19, reichmanj using sbcglobal.net escreveu:
> R Help Forum
> 
> I have output from hierarchal clustering and want to plot the results using
> the ggplot2 function. Where I have a scatter plot with 5 lines representing
> the 5 clusters. I assuming I need to transform the data into three columns
> (like) cluster, variable, and value. Not an issue but was wondering if I
> could plot the data as is.
> 
>    Cluster     A     B     C     D     E     F
>      <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
> 1       1  0.67  0.56  0.54  0.03 -0.97 -1.09
> 2       2  0.52  0.43  0.51  0.05 -0.86 -0.96
> 3       3  0.2   0.3   0.19  0.08  0.02  0.09
> 4       4 -1.3  -1.13 -1.78 -0.05 -0.23 -0.23
> 5       5 -1.6  -1.3  -1.34 -0.23 -0.45 -0.45
> 
> Something like
> 
> Cluster Var	Value
> 1	A	0.67
> 1	B	0.56 etc
> 
>   Then group by cluster??
> 
> Jeff
> 
> ______________________________________________
> R-help using 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.
>



More information about the R-help mailing list