View <- LK_data LK_data$Treatment LK_data$Treatment <- as.factor (LK_data$Treatment) str(LK_data$Treatment) TreatmentID <- as.numeric(LK_data$Treatments) TreatmentID ma <- as.matrix(LK_data[, 2:32]) # convert to matrix disMatarix <- dist(ma) #Distance Matrix Computation plot(hclust(disMatarix)) rownames(ma) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") heatmap(ma, scale = "column", RowSideColors = rainbow(7)[LK_data$Treatment] ) #install.packages("pheatmap") library(pheatmap) ma <- as.matrix(LK_data[1:45, 2:32]) # convert to matrix row.names(ma) <- row.names(LK_data[,1]) rownames(ma) <- rownames(LK_data[, 1]) # assign row names in the matrix pheatmap(ma, scale = "column", clustering_method = "average", # average linkage row.names(LK_data[,1, drop = FALSE]), # the 1st column as color bar show_rownames = TRUE ) pheatmap(ma, scale = "column", clustering_method = "average", # average linkage annotation_row = LK_data [,1, drop = FALSE], # the 1st column as color bar show_rownames = TRUE ) library(pheatmap) ma <- as.matrix(LK_data[, 2:32]) # convert to matrix rownames(ma) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") pheatmap(ma, scale = "column", clustering_method = "average", # average linkage drop = FALSE, # the 1st column as color bar show_rownames = TRUE ) #1-heatmap x <- LK_data x <- as.matrix(AN_data[, 2:26]) rownames(x) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") #2 install.packages("gplots") #3-pheatmaps install.packages("pheatmap") library(pheatmap) pheatmap(x, scale = "column", clustering_method = "average", annotation_col = LK_data[, 1, drop = FALSE], cutree_rows = 6, cutree_cols = 3, show_rownames = FALSE ) max <- cbind(LK_data [,1], ma) heatmap(ma) ma <- as.matrix(LK_data[, 2:32]) rownames(ma) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") LK_data mat = matrix(rnorm(100), 10) rownames(mat) = paste0("R", 1:32) colnames(mat) = paste0("C", 1:32) library(circlize) col_fun = colorRamp2(c(-2,0,2), c("green", "black", "red")) col_fun(seq(-3, 3)) heatmap(mat, name = "mat", col = col_fun) x <- LK_data x <- as.matrix(LK_data[, 2:32]) rownames(x) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") # 2-gplots install.packages("gplots") library(gplots) heatmap.2(x, scale = "column", col = bluered(100),trace = "none") #ggplot2 library(ggplot2) y <- LK_data library(reshape) y1 <- melt (y) x <- LK_data x <- as.matrix(LK_data[, 2:32]) rownames(x) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") heatmap(x, scale ="column") # 2-gplots install.packages("gplots") library(gplots) heatmap.2(x, scale = "column", col = bluered(100),trace = "none") #ggplot2 library(ggplot2) y <- AN_data library(reshape) y1 <- melt (y) library(tidyverse); library(readxl) library(usmap) library(scales) geom_tile() - LK_data ........................ install.packages("pheatmap") library(pheatmap) pheatmap(x, scale = "column", clustering_method = "average", annotation_col = AN_data[, 1, drop = FALSE], cutree_rows = 6, cutree_cols = 3, show_rownames = FALSE ) max <- cbind(LK_data [,1], ma) heatmap(ma) ma <- as.matrix(LK_data[, 2:32]) rownames(ma) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") #install packages for PCA analysis install.packages("factoextra") install.packages("FactoMineR") library(factoextra) library(FactoMineR) # create a principle component table View(LK_data) LK_data.pca1 <- PCA(LK_data[, -1], graph=TRUE, scale.unit = TRUE) #to present most of the data scree plot fviz_eig(AN_data.pca1, addlabels = TRUE, ylim=c(0,80)) #create a correlation plot #PCA plot pcaData <- as.data.frame(pca$xxvii[, 2:32]) # extract first two columns and convert to data frame fviz_pca_var(LK_data.pca1, col.var = "cos2", gradient.col= c("#FFCC00", "#CC9933", "#660033", "#330033","Red", "Pink", "green", "blue", "light blue"), repel = TRUE) + labs(title = "PCA of parameters", x="PC1 (80.1%)", y="PC2 (9.2%)", colour = "Treatment") # create a principle component table LK_data.pca1 <- PCA(LK_data[, -1], graph=TRUE, scale.unit = TRUE) #to present most of the data scree plot fviz_eig(LK_data.pca1, addlabels = TRUE, ylim=c(0,80)) View(LK_data) #create a correlation plot #PCA plot library("FactoMineR") rownames(LK_data.pca1) <- c("B0D0V1","B0D1V1", "B0D2V1", "B0D3V1", "B0D4V1", "B0D0V2", "B0D1V2", "B0D2V2", "B0D3V2", "B0D4V2", "B0D0V3", "B0D1V3", "B0D2V3", "B0D3V3", "B0D4V3", "B1D0V1", "B1D1V1", "B1D2V1", "B1D3V1", "B1D4V1", "B1D0V2", "B1D1V2", "B1D2V2", "B1D3V2", "B1D4V2", "B1D0V3", "B1D1V3", "B1D2V3", "B1D3V3", "B1D4V3", "B2D0V1", "B2D1V1", "B2D2V1", "B2D3V1", "B2D4V1", "B2D0V2", "B2D1V2", "B2D2V2", "B2D3V2", "B2D4V2", "B2D0V3", "B2D1V3", "B2D2V3", "B2D3V3", "B2D4V3") summary(LK_data) library("factoextra") library("ggplot2") eig.val <- get_eigenvalue(LK_data) #Scree Plot fviz_eig(LK_data, addlabels = TRUE, ylim = c(0, 50)) #PCA Variable fviz_pca_var(LK_data.pca1, col.var = "cos2", gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"), repel = TRUE # Avoid text overlapping ) #PCA individual fviz_pca_ind(AN_data.pca1, col.ind = "cos2", gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"), repel = TRUE # Avoid text overlapping (slow if many points) ) #Biplot fviz_pca_biplot(LK_data.pca1, repel = TRUE, col.var = "red", col.ind = "black" ) #Biplot ellipses fviz_pca_biplot(LK_data.pca1, col.ind = LK_data$Treatment, addEllipses = TRUE, label = "Treatment", col.Treatment = "black", repel = TRUE, legend.title = "PCA" ) library("factoextra") library("ggplot2") View(LK_data) LK_data.pca1 <- PCA(LK_data[, -1], graph=TRUE, scale.unit = TRUE) #Biplot ellipses fviz_pca_biplot(LK_data.pca1, col.ind = LK_data$Treatment, addEllipses = TRUE, label = "Treatment", col.Treatments = "black", repel = TRUE, legend.title = "PCA" )