0

hello everyone I am trying to plot the heat map wanted cluster the plot and plot is not looking good wanted change the color i am newbie can any one tell me how can I plot heat-map with clustering values which are showing similar pattern cluster together my data data_link

what i tried simply tried to log normalize the data and plot the graph

library(ggplot2)
library(reshape2)

mydata=read.table("Test_data", sep="\t", header=TRUE)
melted_cormat <- melt(mydata)
head(melted_cormat)
melted_cormat$new=log2(1+melted_cormat$value)
ggplot(data = melted_cormat, aes(x=variable, y=ID, fill=new)) + 
  geom_tile()

is it posible increase each value cell size like below image

please suggest me Thank you

Shrilaxmi M S
  • 151
  • 1
  • 12

1 Answers1

2

You can make a heatmap from this data, but I don't think it will be a very good way to visualize this much data. You have 287 rows in mydata, which means you will have 287 rows in your plot. This will make the individual rows difficult to make out, and it will make labelling of the y axis impossible.

The other issue is that approximately 99% of your values are under 1000, yet your highest value is almost 6000. That means that the scaling of your fill is going to be extremely uneven. It will be difficult to see much detail in the lower ranges.

If you want to see clustering you could use pheatmap instead of ggplot2, and I would probably do a log transform on the fill scale to reveal the details better. However, the problem with simply having too much data on a single plot persists.

mymatrix <- log(as.matrix(mydata[,-1]))
mymatrix[mymatrix < 0] <- 0
pheatmap::pheatmap(mymatrix)

enter image description here


EDIT

If you only plotted the first 10 rows of data, you can see this is more clearly like a heatmap:

pheatmap(as.matrix(mydata[1:10,-1]))

enter image description here

Or the first 30 rows:

pheatmap(as.matrix(mydata[1:30,-1]))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • to put my humble two penny's worth in - not sure with the "too much data" bit - in fact, we (our eyes:) are pretty good in being able to discern tiny data flecks on minimal space. If you have already read Tufte's [The Visual Display of Quantitative Information](https://www.edwardtufte.com/tufte/books_vdqi), this would be referred to as high data density. (and a personal note - if you have not yet read the book, it's a *great(!!)* read. – tjebo Nov 19 '20 at 17:01
  • @Allan Cameron Thank you for the answer, information is clear, is there any clustering method i wanted segregate values if they have similare behaviour, like a box and if value is zero i wanted put perticular color for zero values – Shrilaxmi M S Nov 19 '20 at 17:29
  • @ShrilaxmiMS yes, that's what this plot does. The darker blue squares are the zero values. – Allan Cameron Nov 19 '20 at 17:39
  • 1
    @Tjebo I get that the data is discernable. I just don't think this plot is very informatiive, particularly if one is interested in picking out any one individual on the y axis. Thanks for the book tip - I haven't read that, but will check it out. – Allan Cameron Nov 19 '20 at 17:42
  • okay, but just edited my question plot look like boxes and if values zero, put other color and i wanted to the cluster the rows – Shrilaxmi M S Nov 19 '20 at 17:43
  • @ShrilaxmiMS but this is my point: You have 287 rows of data, so if you want to include all those rows _and_ make each box say 0.5cm high, then your plot would be over a metre tall! You cannot fit this on a normal screen. You can either have all the rows on one plot, all squished up like this, or you can remove some rows and have larger boxes, but you cannot have both. I'll update to demonstrate – Allan Cameron Nov 19 '20 at 17:46
  • @AllanCameron yes for remove some rows i wanted cluster how cluster if values are not in that clustered data i will remove – Shrilaxmi M S Nov 19 '20 at 17:49
  • @ShrilaxmiMS which rows do you want to remove? – Allan Cameron Nov 19 '20 at 17:51
  • I wanted my data arrange like data1 to data6 with serial and rows values to cluster if the rows which will different patern on like increase to decrease those i wanted and rest i will remove – Shrilaxmi M S Nov 19 '20 at 17:55