Skip to content

Plotting function image

5 messages · uday, Etienne B. Racine, ilai

#
I have some data set which has latitude, longitude and Z values. 
I would like to plot them on global map. 
I am thinking to use image 
image(x, y, z, zlim, xlim, ylim, col = heat.colors(12),
      add = FALSE, xaxs = "i", yaxs = "i", xlab, ylab,
      breaks, oldstyle = FALSE, useRaster = FALSE, ...)

here I have x = longitude
                       y= latitude 
                      z = z 

but z suppose to be matrix but my z values are  single array , could
somebody please tell me how to convert these single array of z to matrix ? 



--
View this message in context: http://r.789695.n4.nabble.com/Plotting-function-image-tp4387796p4387796.html
Sent from the R help mailing list archive at Nabble.com.
#
In the absence of data

coords <- expand.grid(lat=1:5,long=1:5)
coords$z <- rnorm(25)
Coords<- unstack(coords,z~long)
image(as.matrix(Coords))
On Tue, Feb 14, 2012 at 10:36 AM, uday <uday_143_4u at hotmail.com> wrote:
#
Hi ,

Thanks for reply 

My latitude and longitude contains 90000-100000 observations per file  
when I run coords <- expand.grid(lat=1:5,long=1:5) then my computer 

*** caught segfault ***
address 0x6951c20, cause 'memory not mapped'

Traceback:
1: .C("spline_eval", z$method, nu = as.integer(n), x =
as.double(xout),     y = double(n), z$n, z$x, z$y, z$b, z$c, z$d, PACKAGE =
"stats")
2: spline(gam.data$x[, col.data], gam.smooths.all$fit[, m], xout =
gam.results.global[m,     , "x.values"], ties = mean)
 3: eval.with.vis(expr, envir, enclos)
 4: eval.with.vis(ei, envir)
5: source(file.path(getwd(), "Skripte", "r",
"GAM_hourly", "1_calcs_GAM_all_sites_hourly.R"),     echo =
TRUE, max.deparse.length = 2e+05)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

so is there any other way to deal with this ?
My main objective to plot this observations on global map 
the sample data is 
lat <- -11.3082 -11.6041 -11.9002 -12.1961 -12.1461 -12.7881 -12.6657
-12.8467 -13.7233 -13.6271
lon<- 135.6423 135.5799 135.5184 135.4558 133.5313 135.3321 134.6688
133.9839 132.0651 131.5528
gas <- 1688.91 1679.24 1677.77 1635.60 1652.77 1663.43 1642.16 1671.84
1674.65 1665.54



--
View this message in context: http://r.789695.n4.nabble.com/Plotting-function-image-tp4387796p4389959.html
Sent from the R help mailing list archive at Nabble.com.
#
Inline
On Wed, Feb 15, 2012 at 3:04 AM, uday <uday_143_4u at hotmail.com> wrote:
You don't have to run this part. As your original post did not provide
any details on data, coords is only a toy example.
I doubt expand.grid was the cause of this crash, and I see no
reference to it in traceback.
Your lat,long do not seem to be forming a uniform grid. ?image would
probably spit an error about "increasing x and y" or something similar
(no access to R on this machine).
You could try
library(lattice)
levelplot(gas~lat+long,data=yourdata)    # data argument is optional
-only if lat,long,gas are columns of a data frame

You may also want to look at the maps package for projections of lat/long

Hope this helps