1

How can I add the color scale on the topright of an exist png image with R code? The color scale is made by "KEGGprofile" R package. The code is:

col = col_by_value(temp, col=colorRampPalette(c('yellow','white','blue'))(1024), range=c(min(temp),max(temp))).

The temp data is:

Proteome    Phosphoproteome
10365   0.1936665   0.8226708
3320    -0.6043064  0.3554265
596 -1.8526172  -0.4719894
6300    1.2375722   1.3151508
659 0.1260142   -0.6054770
858 -1.4846932  1.6420495

The color scale look like this:

enter image description here enter image description here

The exist png image is as follows:

enter image description here enter image description here

How to zoom out and Rotate the color scale figure and paste it into the png imge (Just as follows). The number is the color scale can also be clear.

enter image description here enter image description here

Tung
  • 26,371
  • 7
  • 91
  • 115
Bill Ryan
  • 13
  • 2
  • You could have a look at the `png` package, https://stackoverflow.com/questions/4993189/overlay-data-onto-background-image should help you to get started – Daniel Fischer Aug 09 '18 at 05:17

1 Answers1

0

You can use the function readPNG to read the exist figure, use rasterImage to plot the figure and use image.plot to add the color scale. while the parameter horizontal in image.plot function can Rotate the legend and smallplot can size the legend. By the way, you can adjust the size of legend scale by axis.args parameter.

library(png)
library(graphics)
library(grDevices)
library(fields)

img=readPNG("hsa00310_profile_bg.png")
width=ncol(img)
height=nrow(img)
png(file="hsa00310_profile_bg.png",width=width,height=height)
par(yaxs="i")
par(xaxs="i")
par(mar=c(0,0,0,0))
plot(c(0,width), c(0,height), type='n', xlab="", ylab="")
rasterImage(img, 0, 0, width, height,interpolate=F)
image.plot(legend.only=T, zlim=c(-2,2), col=colorRampPalette(c('yellow', 'white', 'red'))(1024), horizontal 
=TRUE, legend.shrink=0.1, smallplot = c(.9,.99, .92,.95), axis.args = list(cex.axis = 2))
dev.off()

enter image description here

user4672728
  • 96
  • 1
  • 9