world-map-r icon indicating copy to clipboard operation
world-map-r copied to clipboard

resizing area issue

Open lhor opened this issue 6 years ago • 6 comments

Hi Murat, I was trying different combinations of locations, but when I reduced the area to only include latitudes in between 25-50 the map stretches out distorting the image. I tried to resize the PDF but I lost some of the legends. However, it works well if I include samples that span all over the map. I can send you the data file I'm using if necessary. Thanks! Coto

lhor avatar Jun 19 '18 01:06 lhor

Yes, please send me the data file and I'll see whether I can do something quick :)

meren avatar Jun 19 '18 01:06 meren

Cool, I'm attaching the data here. The problem is when you remove a row with a negative latitude (e.g., TARA_093) data.txt

lhor avatar Jun 19 '18 02:06 lhor

I was having maybe a similar issue last night :). I was going to post something anyway so I may as well do it now. Here is my hack for what it's worth--nothing fancy and I literally finally figured it out over coffee this morning.

First I think the resolution of the data in the map_data package are not suitable finer scales. Here is what my image looked like out of the box (after tweaking the MARGIN_MIN/MAX lines to |0.2|. Adjusting the MARGIN_MIN/MAX helped with the distortion but the map still looks funny :) Low_Res_Map

After some looking around I figured that shape file (whatever those are) were my best best. So I downloaded shape file data from GADM . My data is from Panama so I downloaded that dataset.

The directory ("gadm36_PAN ) has a bunch of files that collectively make up the shape data. I have no idea what any of this means yet. With this data I made a few tweaks to @meren 's code, specifically to lines 43-57 so that it looked like this:

gen_blank_world_map <- function(df) { s <- shapefile("gadm36_PAN/gadm36_PAN_3")#This is where the shape file data is stored world_map <- fortify(s)

min_lat <- min(df$Lat) + MARGIN_MIN_LAT max_lat <- max(df$Lat) + MARGIN_MAX_LAT min_lon <- min(df$Lon) + MARGIN_MIN_LON max_lon <- max(df$Lon) + MARGIN_MAX_LON

p <- ggplot() p <- ggplot(data=world_map,aes(x=long, y=lat, group=group)) p <- p + geom_polygon(fill = '#777777', size = 10) p <- p + coord_map(projection = "mercator", xlim = c(min_lon, max_lon), ylim = c(min_lat, max_lat))

return(p) }

I also needed a few additional libraries (library(raster), and library(rgdal)) and here is the new image: Hi_Res_Map

I am still tweaking the font and point size but you get the idea. Thanks @meren for another amazing tool!

Jarrod

jarrodscott avatar Jun 19 '18 12:06 jarrodscott

Hi @jarrodscott, thank you very much for this solution! Using your approach, I updated the code and the README:

https://github.com/merenlab/world-map-r/blob/master/README.md#generating-high-resolution-maps

@lhor, please try this and let us know whether it works.

Best wishes,

meren avatar Jun 19 '18 14:06 meren

very elegant. this rocks

jarrodscott avatar Jun 19 '18 14:06 jarrodscott

cool solution, @meren! It works well for well-defined areas (i.e., countries) but I wasn't able to make it work for a transect that covers US-ocean-Europe. I was also trying to use a world map (yes, there is a shape for it too) but my MacBook ran out of memory! I might try later on the cluster. Thanks!

lhor avatar Jun 21 '18 01:06 lhor