简体   繁体   中英

Heatmap in R, representation of colors and removal of x-axis

I made a heatmap. The code I used is:

 heatmap(t(data.matrix(survey)))

在此处输入图片说明

I don't need anything on x-axis. In plots, the following command would delete the numbers in x-axis:

  xaxt='n'

Also, if I want to add a chart at the top (which tells about the representation of colors - like yellow means lower values and red means higher), how can I do that? I have no idea so I didn't even try. The only thing I can think of is 'scale' but that didn't work.

Lastly, I tried to change the color (green and red) and for that I used:

  mycol = c("green","red")
  heatmap(t(data.matrix(zscoreplus)),col=mycol)

在此处输入图片说明 Unlike 1st pic, there are no colors in between. (1st one had a lot more variety.) What I was trying to get was red, light red, reddish-green, green, dark green, etc...

ps For some reason, gplots and heatmap.2 are not installed and R can not find those packages.

Instead of using the basic heatmap() function, you could load the gplots package and use heatmap.2() - in your case same syntax - to get a color key. Let me know if you have any further questions about the heatmap.2() package.

EDIT:

Sorry, didn't read that you cannot install gplots . Is it because of limited admin rights?

Unfortunately, heatmap() is kind of limited regarding the color key.

But for the red -> green problem I have a solution for you. To create your own color palette, try

my_palette <- colorRampPalette(c("red", "green"))(n = 1000)

and then use it as color in your heat map: heatmap(..., col = my_palette, ...)

How important is clustering in your case? If you don't need clustering, you can use the levelplot() function (comes with R), which has a nice color key representation.

EDIT2: Regarding the color "scale" problem. I assumed that you mean something like legend according to the description in your first post. So is something like in the screenshot below that you want?

在此处输入图片说明

EDIT3 Regarding the x-labels: Unfortunately, there is no direct option in heatmap.2() to turn those off. THose x-labels are the colnames for your matrix that you read in. By xlabel you would just control the general description of the axis (it is turned off by default). Here is a Screenshot that shows what I mean when xlabels is used:

在此处输入图片说明

Maybe you could just give your matrix empty ( " " ) colnames . That should help. On the other hand, I am sorry to ask you this, but this doesn't make sense if you are using clustering. How would you know which is which? An alternative solution is to simply crop the region or code from the pdf , or svg once you saved the heat map. Shouldn't take more than 5 seconds.

Regarding your problems to install gplots : You forgot the quotes.

require(gplots) Loading required package: gplots Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'gplots' > install.packages(gplots) Error in install.packages : object 'gplots' not found – ayesha malik 8 mins ago

Try

install.packages("gplots", dependencies = TRUE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM