Analysis in R: Helps color labels in dendrograms. The “colorhcplot” package

RAnalytics
スポンサーリンク

This package is useful for color-coding dendrogram labels in groups.

Package version is 1.3.. Checked with R version 4.1.2.

スポンサーリンク

Install Package

Run the following command.

#Install Package
install.packages("colorhcplot")

Example

See the command and package help for details.

#Loading the library
library("colorhcplot")

###Creating Data#####
set.seed(1234)
n <- 10
TestData <- data.frame(row.names = paste0("ID", 1:n),
                       Group = as.factor(sample(paste0("Group", 1:3),
                                                n, replace = TRUE)),
                       Test_A = rnorm(n), Test_B = rnorm(n), Test_C = rnorm(n))
########

#Distance Calculation
#Loading the amap package to use the Spearman method
#Install the amap package if it is not already present
if(!require("amap", quietly = TRUE)){
  install.packages("amap");require("amap")
}
#Calculation
DistData <- Dist(TestData[, -1], method = "spearman")

#Clustring
#method option:"ward.D","ward.D2","single","complete","average",
#"mcquitty","median","centroid"
hTestData <- hclust(DistData, method = "complete")
########

#Plot the dendrogram: colorhcplot command
#Data:hc option
#Specify group data:fac option
#Specify hang value:hang option: negative value makes the label bottom
#Direction of y-axis labels:las option; 1:vertical,0:horizontal
colorhcplot(hc = hTestData, fac = TestData[, 1],
            hang = -1, main = "Karada Good",
            lab.cex = 1.3, lwd = 2, las = 1,
            color = c("chartreuse2", "orange2", "blue"))

Output Example

・colorhcplot command


I hope this makes your analysis a little easier !!

Amazon audibleの登録の紹介

プライム会員限定で2024年7月22日まで3か月無料体験キャンペーン開催中です。無料体験後は月額1,500円で聞き放題です。なお、聞き放題対象外の本はAudible会員であれば非会員価格の30%引きで購入することが可能です。

Amazon audibleはプロのナレーターが朗読した本をアプリで聞くことができるサービスで、オフライン再生も可能です。通勤や作業のお供にAmazon audibleのご登録はいかがでしょうか。

・AmazonのAudible

https://amzn.to/3L4FI5o

Copied title and URL