Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resizing area issue #1

Open
lhor opened this issue Jun 19, 2018 · 6 comments
Open

resizing area issue #1

lhor opened this issue Jun 19, 2018 · 6 comments

Comments

@lhor
Copy link

lhor commented Jun 19, 2018

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

@meren
Copy link
Member

meren commented Jun 19, 2018

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

@lhor
Copy link
Author

lhor commented Jun 19, 2018

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

@jarrodscott
Copy link

jarrodscott commented Jun 19, 2018

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

@meren
Copy link
Member

meren commented Jun 19, 2018

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,

@jarrodscott
Copy link

very elegant. this rocks

@lhor
Copy link
Author

lhor commented Jun 21, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants