Hi

I have a question about how to make cluster for relative expression (on read counts) using k-means clustering, I couldn't find any good manual for solving this problem.

I need to make a plot like below: to have different cluster on genes count:

Does anybody know how to make it?

![enter image description here][1] 


  [1]: https://i.postimg.cc/qRmPVccS/Screen-Shot-1397-07-20-at-20-13-12.png
I have solved the problem, the code should be something like below:

You need to run DESeq2 before processing rowMeans:


    library(ggplot2)
    library(DESeq2)
    #suppose you have one column per each time/tissue condition
    
    cds <- DESeq(cds)
    vst <- getVarianceStabilizedData(cds)
    df <- vst
    df <- df - rowMeans(df)
    df <- as.data.frame(df)
    colnames(df)
    res_km <- kmeans(df, 5, nstart = 10)
    data_plot <- data.table(melt(data.table(class = as.factor(res_km$cluster), df)))
    data_plot[, Time := rep(1:ncol(df), each = nrow(df))]
    data_plot[, ID := rep(1:nrow(df), ncol(df))]
    head(data_plot)
    # prepare centroids
    centers <- data.table(melt(res_km$centers))
    setnames(centers, c("Var1", "Var2"), c("class", "Time"))
    centers[, ID := class]
    centers[, gr := as.numeric(as.factor(Time))]
    head(centers)
    head(data_plot)
    # plot the results
    ggplot(data_plot, aes(variable, value, group = ID)) +
      facet_wrap(~class, ncol = 2, scales = "free_y") +
      geom_line(color = "grey10", alpha = 0.65) +
      
      geom_line(data = centers, aes(gr, value),
                color = "firebrick1", alpha = 0.80, size = 1.2) +
      labs(x = "Time", y = "Load (normalised)") +
      theme_bw()

