I have a csv file loaded in R as the follow example below. I trying to assign projection. Then, plot map and draw pie for species variable for each grid cell.

Month    long      lat  variable   value
3       48.0000 -12.8800 SKJTotal  10.990
3       47.8800 -13.0800 SKJTotal   5.127
3       48.0000 -13.0000 YFTTotal   4.576
3       48.0000 -13.0200 SKJTotal   4.240
5       42.6800 -12.5700 SKJTotal  10.838
5       41.8700 -11.4800 SKJTotal  13.615
5       45.3200 -14.6300 BETTotal  13.615
5       45.6800 -14.1300 SKJTotal  21.675
5       42.5500 -11.7200 SKJTotal   6.130
5       45.5000 -13.7000 BETTotal  43.350
5       41.7800 -11.6300 YFTTotal  74.878

I used the codes below to assin the projection.

coordinates(mpma) = ~long+lat # trying to assign the projection
proj4string(mpma) <- CRS("+proj=longlat +datum=WGS84")

The summary from overall csv file this one below.

Object of class SpatialPointsDataFrame
        min   max
long  34.00 49.35
lat  -27.33 -9.93
Is projected: FALSE 
proj4string :
[+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0]
Number of points: 27054
Data attributes:
     variable        value         
 SKJTotal:9018   Min.   :  0.0000  
 YFTTotal:9018   1st Qu.:  0.0000  
 BETTotal:9018   Median :  0.4575  
                 Mean   :  6.1566  
                 3rd Qu.:  6.0000  
                 Max.   :412.4290

Then, I try to plot the map using normal plot as follow:

map(add = T,fill=T,col="grey")

The returning map is not projected.

How do I fix the projection?

I have been tried many codes without success. I also tried to use the world basemap setting the long=c(30,50) and lat=c(-30,-9). But here the output map as very small. And I can't find the code to zoom or increase the resolutions. I intend to draw grids and draw pies for each grid cells.

  • 1
    Use spTransform(mpma, crs_proj4string_of_your_choice) - this modifies the coordinates. The assignment you do above is merely nominating the right coordinate system the data is currently in.
    – mdsumner
    Aug 23 '17 at 21:35

Don't do:




What you've done gets the long and lat values and plots them like they are any two vectors in R, like you were making a scatterplot. If you plot the object then R goes "Ooh, its a spatial object, I better treat it right" and sets up the axes correctly for a map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.