[R-sig-Geo] Plotting Data the globe

Pierre Roudier pierre.roudier at gmail.com
Wed Apr 27 06:17:13 CEST 2011


Hi,

It is not clear to me why you do not make use of the sp package. It is
not clear what projection your data is in, I assume it is geographic
coordinates/WGS84. Let's say you have your data in a data.frame called
df, with columns lat, lon and z:

set.seed(0)
npts <- 100
lon <- runif(n=npts, min=-180, max=180)
lat <- runif(n=npts, min=-90, max=90)
z <- rnorm(n=npts, mean=10, sd=5)
df <- data.frame(lon, lat, z)

library(sp)
coordinates(df) <- ~lon+lat

# you can plot it already:
spplot(df, zcol='z')

# let's add some information about the data projection:
proj4string(df) <- CRS("+init=epsg:4326")

# if you want to use the Mollveide projection, we have to change projection:
library(rgdal)
df.proj <- spTransform(df, CRS("+proj=moll +lon_0=0 +x_0=0 +y_0=0
+ellps=WGS84 +datum=WGS84 +units=m +no_defs"))

# Plot it again
spplot(df.proj, zcol='z')

# change the color scheme
spplot(df.proj, zcol='z', col.regions=rainbow(64))

Hope this help,

Pierre

2011/4/27 sourav sengupta <aritra.sourav at gmail.com>:
> Hello everyone,
>
> I have a big data set with latitude, laongitude and the values (Z). I want
> to plot the data on a map using a color scheme, so that the color at a
> particular lat-long value depends on the Z-value.
>
> First I used a projection to get the x-y coordinates. Then defined a color
> scheme, and made a scatter plot.
>
> rescale(as.numeric((data$z))) -> z
> coords <- mapproject(data$lon, data$lat, projection="mollweide",
> parameters=NULL, orientation=NULL)
> plot(coords$x, coords$y,col=gray(seq(0,10,,11)/10)[abs(10*(1-z))])
> map("world", projection="",add=TRUE)
>
> This is creating the plot for me, but the quality is very bad. I am not able
> to make it look really smooth. I even used pch="." but that made it very
> grainy. Can anyone help me in this regard? Thanks.
>
> -Aritra
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Scientist
Landcare Research, New Zealand



More information about the R-sig-Geo mailing list