6

I have created a image plot for this data:

sample
         p         p.1         p.2         p.3         p.4
  p    1.0000000  0.24077171 -0.66666667 -0.49009803  0.61237244
  p.1  0.2407717  1.00000000  0.09028939 -0.83444087  0.14744196
  p.2 -0.6666667  0.09028939  1.00000000  0.21004201  0.10206207
  p.3 -0.4900980 -0.83444087  0.21004201  1.00000000 -0.08574929
  p.4  0.6123724  0.14744196  0.10206207 -0.08574929  1.00000000

Using this code:

  image.plot(sample,col=redblue(191), zlim=c(-1,1))

I get this image:

Instead of 0.0 0.2 0.4.. on x and y axes, I want p p.1 p.2... How do I get that that? Thank you for your time and consideration?

My heatmap looks like this:

enter image description here

its not symmetric. Can you please fix this? I am using this code:

shades=c(seq(-1,-0.5,length=64), seq(-0.5,0.5, length=64), seq(0.5,1,length=64))
heatmap.2(sample, dendrogram='none', symm=TRUE, Rowv=FALSE, Colv=FALSE, key=TRUE, cexCol=0.7, cexRow=1,scale="row", keysize=1, col=redblue(191), breaks=shades)

Swapnil 'Tux' Takle
  • 1,187
  • 2
  • 9
  • 9
  • 1
    I sort of found a way to do it, but it's not very straightforward: `image.plot(sample,col=rainbow(25), zlim=c(-1,1), axes=F); title(main="Graph"); axis(1, at=seq(0,0.8,0.2), labels=rownames(sample)); axis(2)` For some reason, I wasn't able to directly make the x-axis labels. But after I used title(), I was allowed to create the x-axis labels. Someone might know how to do it more elegantly. – Alex May 27 '12 at 03:42

1 Answers1

10

Here is a better-ish solution:

 par(mar=c(5,4.5,4,7))
 image(sample, col=rainbow(25), axes=F)  #redblue() doesn't work on my computer.
 axis(2)
 axis(1, at=seq(0,0.8,0.2), labels=rownames(sample))
 image.plot(sample, legend.only=T)

enter image description here

EDIT: Does the plot below look like what you are looking for?

 sample = cor(matrix(rnorm(400), nrow=20))
 image(cor(matrix(rnorm(400), nrow=20)), axes=F)
 mtext(text=c(paste("country",1:21)), side=2, line=0.3, at=seq(0,1,0.05), las=1, cex=0.8)
 mtext(text=c(paste("country",1:21)), side=1, line=0.3, at=seq(0,1,0.05), las=2, cex=0.8)
 image.plot(sample, legend.only=T)

enter image description here

Alex
  • 4,030
  • 8
  • 40
  • 62
  • Sorry, but this not the way I want it. I want it the way it shows in heatmap, is it possible? I am unable to use heatmap because it produces unsymmetric plot – Swapnil 'Tux' Takle May 27 '12 at 05:06
  • Could you show a sample heatmap so we know exactly what you are looking for. – Alex May 27 '12 at 05:19
  • I have edited my question and included my heatmap image and the code which i am using. Thank you for your help. – Swapnil 'Tux' Takle May 27 '12 at 05:56
  • @Swapnil'Tux'Takle -EDIT: actually even your original code produced a symmetrical plot for me...Not sure what your problem really is.. – Alex May 27 '12 at 06:43
  • can you please give me the code you used and upload the plot you got? I might be able to figure something out from it. – Swapnil 'Tux' Takle May 27 '12 at 07:16
  • I figured out the answer for heatmap, scale="row" was the problem. I removed it and its fixed. – Swapnil 'Tux' Takle May 27 '12 at 08:51
  • Oh yes, that's right. Because I got an error message about scale="row", I removed it and forgot to mention it. Good that it's working for you now. – Alex May 27 '12 at 10:34