# The following R commands are associated with the clustering analysis described in �gComprehensive and quantitative analysis of intracellular structure polarization at the apical-basal axis in elongating Arabidopsis zygotes�h by Hiromoto et al.

# Set the working directory to the location of your data files. Replace the placeholder with the actual path.
setwd("<Path to directory>")

# Import the data. Be sure to replace the placeholder with your actual data file name.
groups <- read.csv("<Data file name.csv>", header = TRUE, row.names="ID", stringsAsFactors = FALSE)

# Perform normalization on the data.
n_groups <- scale(groups)

# Load the gplots library for visualization.
library(gplots)

# Create a heatmap, which also includes hierarchical clustering using Ward�fs method.
hv <- heatmap.2(n_groups, hclustfun = function(n_groups){hclust(n_groups, method = "ward.D2")}, col = colorRampPalette(RColorBrewer::brewer.pal(n = 9, name = "YlOrRd"))(10), density.info = "none", trace = "none")

# Export the row labels, which correspond to clustered data points.
dendrorow <- row.names(n_groups)[hv$rowInd]
write.csv(dendrorow, "<Path to output file>")

# Similarly, export the column labels.
dendrocol <- colnames(n_groups)[hv$colInd]
write.csv(dendrocol, "<Path to output file>")

# Extract dendrogram information from the heatmap for further analysis.
hc_heat <- as.hclust(hv$rowDendrogram)

# Classify the data based on the clustering results and export these classifications.
cut <- cutree(hc_heat, k=2)
write.csv(cut, "<Path to output file>")