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

Quick approximation for map projections #922

Merged
merged 4 commits into from
Mar 25, 2014
Merged

Conversation

jiho
Copy link
Contributor

@jiho jiho commented Feb 27, 2014

Instead of reprojecting everything, we just set the aspect ratio of the plot
to the ratio between the length of one degree of lat over one degree of lon.

Edit on 2014-02-27: rebased on head + latest version of roxygen

jiho added 2 commits February 27, 2014 17:42
Instead of reprojecting everything, we just set the aspect ratio
of the plot to the ratio between the length of one degree of lat
over one degree of lon.
The latest version of roxygen figures out S3 methods on its own
@jiho
Copy link
Contributor Author

jiho commented Feb 27, 2014

Now passes devtools::check(). Should have tested before, sorry. Do you prefer one commit?

@@ -0,0 +1,65 @@
#' Cartesian coordinates with an aspect ratio approximating mercator projection.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Mercator?

@hadley
Copy link
Member

hadley commented Mar 13, 2014

  • Motivate the change in one paragraph, and include it in NEWS.
    In parentheses, reference your github user name and this issue:
    (@hadley, #1234)
  • Check pull request only includes relevant changes.
  • Use the official style.
  • Update documentation and re-run roxygen2
  • Add minimal example, if new graphical feature

@jiho
Copy link
Contributor Author

jiho commented Mar 21, 2014

BTW, this one is ready to be pulled I think.

Examples:
coord_map
image
coord_quickmap
image

If there is one thing left I'd like to change it would be the suppress the minor grid as in coord_map but I have no idea how to do this from within a coord function.

@hadley
Copy link
Member

hadley commented Mar 21, 2014

I wonder if it's worth noting that it's hard to see the difference between the two plots of NZ not because it's at a moderate latitude, but because the base file is already very detailed.

It might be worth plotting a rectangle bounding NZ to more clearly show the difference.

@jiho
Copy link
Contributor Author

jiho commented Mar 22, 2014

I'm not sure it's about the details, it's really about the latitude and the extent of the region.

Here is the code with a bounding box:

if (require("maps")) {
# Create a lat-long dataframe from the maps package
nz <- map_data("nz")
# Compute the bounding box
nz_bb <- nz[chull(nz[,c("long","lat")]),]
# Prepare a plot of the map
nzmap <- ggplot(nz, aes(x = long, y = lat)) +
  geom_polygon(data = nz_bb) + 
  geom_polygon(aes(group = group), fill = "white", colour = "black")

# Plot it in cartesian coordinates
nzmap
# With correct mercator projection
nzmap + coord_map()
# With the aspect ratio approximation
nzmap + coord_quickmap()

coord_map
image
coord_quickmap
image

@hadley
Copy link
Member

hadley commented Mar 23, 2014

I meant a rectangular bb so that you could see the difference. NZ might be a bad example but it'd be nice to have one

@jiho
Copy link
Contributor Author

jiho commented Mar 24, 2014

The difference is actually fairly small for anything under moderate latitudes. Even for the full US it's noticeable only for the northern states (that actually makes the functionality more appealing!). I guess it would show for northern canada or russia but this data is not in maps so it is difficult to make a self contained example.

@jiho
Copy link
Contributor Author

jiho commented Mar 24, 2014

Example:
image
image

@jiho
Copy link
Contributor Author

jiho commented Mar 24, 2014

Would that be better?

northern <- map_data("world")
northern <- northern[northern$lat > 50 & northern$lat < 80,]
northernmap <- ggplot(northern, aes(x = long, y = lat, group = group)) +
  geom_path()
northernmap + ggtitle("raw")
northernmap + coord_map() + ggtitle("coord_map")
northernmap + coord_quickmap() + ggtitle("coord_quickmap")

image
image
image

But coord_map has problems here...

@hadley hadley merged commit f0b42e9 into tidyverse:master Mar 25, 2014
@hadley
Copy link
Member

hadley commented Mar 25, 2014

Yeah, doesn't seem to be an easy way to generate a nice example, so lets not worry about it.

@jiho jiho deleted the quickmap branch March 25, 2014 23:19
@jiho
Copy link
Contributor Author

jiho commented Mar 25, 2014

Great. Thanks for merging it! It'll be useful to be able to use this one for one class in which we produce a lot of tiled maps which coord_map made very long to plot and with (very thin but noticeable) white space showing between the tiles.

@lock
Copy link

lock bot commented Jan 19, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants