[R-sig-Geo] Adding Scale bar in the Image
Roger Bivand
Roger.Bivand at nhh.no
Thu May 1 20:40:43 CEST 2008
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.
> Thanks for prompt reply. Anyway to be a absolutely certain here I am
> giving overview of my data type. My data has a four column of which 1
> and 2 are coordinates in meters. Where as 3rd to 6th are reflectances in
> 4 bands. Here I am using 3rd to 5th bands to plot the (RGB) image of my
> study area. So here I want to add scale bar and if possible bar plot
> also with color range as displayed in the image. I would be thankful if
> you suggest me wayout.
> Thanking you
> Pujan
>
> My programme code:
No, you said:
library(rimage)
first, but that wasn't obvious, was it?
> A<- matrix (scan("test.txt",n=29613*6,sep="",skip=8),29605,6,byrow=TRUE)
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
> greenchannel<-matrix(A[,3],nrow=155,ncol=191,byrow=TRUE)
> redchannel<-matrix(A[,4],nrow=155,ncol=191,byrow=TRUE)
> nearinfraredchannel<-matrix(A[,5],nrow=155,ncol=191,byrow=TRUE)
> midinfraredchannel<-matrix(A[,6],nrow=155,ncol=191,byrow=TRUE)
> mat <- array(0,c(155,191,3))
> mat[,,1] <- nearinfraredchannel/1000
> mat[,,2] <-redchannel/1000
> mat[,,3] <-greenchannel/1000
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
> plot(imagematrix(mat))# To plot image in Color.
> axis(1,col.axis=?blue?,font.axis=4)
> axis(2,col.axis=?blue?,font.axis=4)
> title(main = list(" COLOR IMAGE", font = 4,col=?Blue?), xlab=list(?E-W Direction (Unit in Meters)?,font=3,col=?blue?),ylab= list(?N-S Direction (Unit in Meters)?, font=3,col=?blue?))
>
> _________________________________________________________________
> Spell a grand slam in this game where word skill meets World Series. Get in the game.
> http://club.live.com/word_slugger.aspx?icid=word_slugger_wlhm_admod_april08
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list