[R] plotting over a raster image with control over location and orientation

ravi rv15i at yahoo.se
Fri Aug 21 16:30:32 CEST 2015


Hi,I would like to get some help in plotting over an image. I have a png image over which I would like to have a plot. I would like to be able to control the location, area and orientation of the plot on the image.
I have taken help from the following references :http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Murrell.pdfhttp://stackoverflow.com/questions/12918367/in-r-how-to-plot-with-a-png-as-background
In order to give a reproducible example, I set up my image with the help of some code from the the first reference above.

#Setting up the initial example raster image
x <- y <- seq(-4*pi, 4*pi, len=27)
r <- sqrt(outer(x^2, y^2, "+"))
z <- cos(r^2)*exp(-r/6)
image <- (z - min(z))/diff(range(z))
step <- diff(x)[1]
xrange <- range(x) + c(-step/2, step/2)
yrange <- range(y) + c(-step/2, step/2)
plot(x, y, ann=FALSE,xlim=xrange, ylim=yrange,xaxs="i", yaxs="i")
rasterImage(image,xrange[1], yrange[1],xrange[2], yrange[2],interpolate=FALSE)

# the explanation of my problem starts here
# First, I want to mark out a particular line
lines(c(10,10.5),c(-10.5,10),col="red",lwd=2)
#In my problem, I have to locate these points graphically from the image
calpoints <- locator(n=2,type='p',pch=4,col='blue',lwd=2)
# this gives the line corresponding to the x-axis for my overlay plot
# I don't want the red line on my plot
#the red line plotted earlier is just to show the example location
newOrigin<-calpoints[1]
xLimit<-calpoints[2]#xlimit marks the limit of the x-axis on the image# on this new line as the x-axis, I want to make a new plot# the y-axis should be perpendicular to the x-axis. I would like to be able to specify the width of coverage over the image#example
xx<-1:10
yy<-xx^2
plot(xx,yy,xlim=range(xx),ylim=range(yy),col="blue",type="b",xlab="x",ylab="square of x")
# I would prefer to have the image more transparent just under the x and y labels and axis labelsThanks, Ravi


	[[alternative HTML version deleted]]



More information about the R-help mailing list