Skip to content
Prev 3519 / 29559 Next

Adding Scale bar in the Image

On Thu, 1 May 2008, PUJAN RAJ REGMI wrote:
If you ask a question on the list, unless there are very good reasons, 
reply through the list. Otherwise you deprive others on the list of 
information, and break the thread. I have brought this back onto the list, 
but the thread is probably broken.

In fact, this thread was broken by you intially, because you simply took 
an existing list message and replied to it, changing the Subject:, but 
still writing to the original contributors. The R lists have instructions 
and a posting guide, please do read them and keep to them.

List archives are searchable and are a potentially valuable resource, 
which loses value if users do not start fresh threads when the subject is 
new, and take follow-ups off-list, depriving others of potentially useful 
information.
No, you said:

library(rimage)

first, but that wasn't obvious, was it?
What about:

A <- read.table("test.txt", skip=8, header=FALSE)
names(A) <- c("x", "y", "greenchannel", "redchannel",
   "nearinfraredchannel", "midinfraredchannel")
library(sp)
coordinates(A) <- c("x", "y")
gridded(A) <- TRUE
then

A$red <- A$nearinfraredchannel/1000
A$green <- A$redchannel/1000
A$blue <- A$greenchannel/1000

image(A, red="red", green="green", blue="blue")
axis(1, col.axis="blue", font.axis=4)
axis(2, col.axis="blue", font.axis=4)

using the image() method for SpatialPixelsDataFrame objects, then the base 
graphics approach as before - use locator() to find the offset. This is 
untried, because you did not either show a publically available data set, 
or provide a (subsetted) copy of your own.

For your bar plot, see layout() or ?par - see the mfrow= argument to add 
another plot to the graphics device.

Roger