-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.r
34 lines (27 loc) · 1.01 KB
/
generator.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Load necessary libraries
library(ggplot2)
library(ggdendro)
library(dendextend)
# Function to read CSV and generate dendrogram
generate_dendrogram <- function(csv_file) {
# Read the CSV file
data <- read.csv(csv_file, row.names = 1)
# Perform hierarchical clustering
distance_matrix <- dist(data) # Compute distance matrix
clustering <- hclust(distance_matrix) # Perform hierarchical clustering
# Convert to a dendrogram object
dendro <- as.dendrogram(clustering)
# Create a ggplot object for the dendrogram
gg_dendro <- ggdendrogram(dendro, rotate = TRUE, size = 2) +
labs(title = "Dendrogram of Clustering",
x = "Samples",
y = "Height") +
theme_minimal()
# Plot the dendrogram
print(gg_dendro)
# Save the plot to a file
ggsave("dendrogram.png", plot = gg_dendro, width = 10, height = 8)
}
# Example usage
csv_file_path <- "C:\\Users\\Max\\NLP4RE\\Dendogram-Generator\\static\\csv\\WhatsApp_bert_cosine_average_results.csv"
generate_dendrogram(csv_file_path)