Skip to content
Prev 322465 / 398500 Next

How to make a raster image in R from my own data set

Hi Kristi,

it takes a few extra steps to create a raster layer from your example 
data set, as it is not a gridded map in Lat lon (probably in some 
projection though). How exactly to do it depends on your data, but here 
are some hints:

1. If you actually need to read the data set from a link, then 
read.table.url is depreceted, just use read.table. You might need to 
call setInternet2(TRUE) first, as the example data is on an https-url.
2. Raster can read a range of inputs, but I am not sure if .csv is one 
of them, and definitely not if the data is not gridded. You can then 
first do interpolation with a Spatial*-object. Set the coordinates of 
your object, this creates a Spatial*-object, and add the projection:
coordinates(pts) = ~lon+lat
proj4string(pts) = CRS("+proj=longlat +datum=WGS84")
3. You will have to create your reference grid (spsample, from raster, 
or another existing grid you have available), and interpolate to this 
grid, using one of the many interpolation packages, such as geoR, 
automap, gstat, intamap.
4. The resulting object can easily be converted to raster through 
raster(interpolationResult[,resultname])

I hope this can help you getting started.
Generally you get quicker response to spatial questions from the 
r-sig-geo list.

Jon
On 24-Apr-13 16:56, Kristi Glover wrote: