map_data objects are no longer spatial objects?

25 views
Skip to first unread message

Paulo Eduardo Cardoso

unread,
Nov 24, 2009, 2:57:56 PM11/24/09
to ggplot2
Otherwise changing aspect ratio of device should not change plot
ratio. It lacks the spatial representation interest. We cannot be sure
if a spatial object will be represented according to its projected or
geographical coordinates.

hadley wickham

unread,
Nov 24, 2009, 3:41:59 PM11/24/09
to Paulo Eduardo Cardoso, ggplot2
Hi Paulo,

Yes, because I've never been able to find out how to calculate the
aspect ratio correctly. If you could provide me with a reference I
could look into it.

Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2



--
http://had.co.nz/

smu

unread,
Nov 24, 2009, 4:04:22 PM11/24/09
to hadley wickham, Paulo Eduardo Cardoso, ggplot2
Hi Hadley,

what do you mean by aspect ratio?

I would say one degree in latitude directions should have the same width
in the plot as one degree in longitudinal direction, but maybe I missed
the point.

regards,
stefan

Nicholas Lewin-Koh

unread,
Nov 24, 2009, 6:07:10 PM11/24/09
to hadley wickham, Paulo Eduardo Cardoso, ggplot2
Hi,
Without projecting the data latitude and longitude are coordinates on a
sphere.
In the spirit of separating the data from the plot, one should project
prior to plotting.
In general for maps an aspect ratio of 1 is appropriate. Let the
projection
handle the stretching. So if you want to plot the world flat, you need
to project
it first.

Nicholas

On Tue, 24 Nov 2009 14:41 -0600, "hadley wickham" <h.wi...@gmail.com>
wrote:

Paulo Eduardo Cardoso

unread,
Nov 24, 2009, 9:41:32 PM11/24/09
to ggplot2
Hi Hardley,

This is something to think about. I don't know how ggplot2 manage to
plot cartesian coordinates or what is happening when we set a coord_map
().

We'd need to know how ggplot2 deals generally with the relation
between plot region/aspect ratio.

There are a lot of considerations about this issue. I agree that
projecting data should precede plotting. In doing so, coordinates
should no longer be presented in degrees as default, as some examples
of coord_maps. For New Zealand for example there is no mention to wich
Datum is being used, NZGD49, NZG200 or WGS84. The geocentric Datum
should always be refered for unprojected data; possibly GRS80,
although differences between NZG2000 and GRS80 (or WGS84) are
negligible. When presenting projected data, the Lat long grid shown
is meaningless, as I understand it. New Zealand Mercator projection
Grid could be printed instead. Did you crossed your outputs with GIS
ones?
Maps shown at coord_maps are beautiful but lacks the desired spatial
integrity and coherent scaling.


Back to proportions and aspect ratio, Can't the approach be the same
used when plotting a SPDF?



Something interesting to explore.

Paulo

On Nov 24, 8:41 pm, hadley wickham <h.wick...@gmail.com> wrote:
> Hi Paulo,
>
> Yes, because I've never been able to find out how to calculate the
> aspect ratio correctly.  If you could provide me with a reference I
> could look into it.
>
> Hadley
>
> On Tue, Nov 24, 2009 at 1:57 PM, Paulo Eduardo Cardoso
>

Paulo Cardoso

unread,
Nov 26, 2009, 11:07:12 AM11/26/09
to ggplot2
Just an exercise
 
I reproduced some of the examples presented at http://had.co.nz/ggplot2/coord_map.html in a GIS. Plots presented are, in some cases, quite different from expected, as you can see from attached PDF.
This is relevant for anyone interested in presenting cartographic maps via ggplot.
 
Paulo
 
2009/11/25 Paulo Eduardo Cardoso <pauloed...@gmail.com>



--
_______________
Paulo E. Cardoso
Layout Projections New Zealand.pdf

hadley wickham

unread,
Nov 29, 2009, 5:31:43 PM11/29/09
to Nicholas Lewin-Koh, Paulo Eduardo Cardoso, ggplot2
> Without projecting the data latitude and longitude are coordinates on a
> sphere.
> In the spirit of separating the data from the plot, one should project
> prior to plotting.
> In general for maps an aspect ratio of 1 is appropriate. Let the
> projection
> handle the stretching. So if you want to plot the world flat, you need
> to project
> it first.

Hmm, ok, so I just need to make sure that coord_map also includes the
functionality of coord_equal. Shouldn't be too hard.

I'll add it to my to do list.

Hadley

--
http://had.co.nz/

JiHO

unread,
Dec 6, 2009, 7:11:47 PM12/6/09
to Paulo Eduardo Cardoso, ggplot2
On Wed, Nov 25, 2009 at 03:41, Paulo Eduardo Cardoso
<pauloed...@gmail.com> wrote:
> This is something to think about. I don't know how ggplot2 manage to
> plot cartesian coordinates or what is happening when we set a coord_map
> ().
>
> We'd need to know how ggplot2 deals generally with the relation
> between plot region/aspect ratio.

I must admit I was never sure of what exactly coord_map() was doing.
What's sure is that the aspect ratio should indeed no change when the
size of the plotting window changes (which it currently does). I
think/hope this is what Hadley is referring to when he talks about
"integrating the functionality of coord_equal to coord_map". This
would allow for further testing of this potentially very cool
functionality.

I have been plotting quite a few lat/lon based maps, in particular
within a GIS class (so we had directly comparisons). The method that I
found to be most reliable was to use:
coord_equal(ratio=cos(mean(latitude)*pi/180))
this works with latitude in decimal degrees, on small enough maps, far
enough from the poles. So of course, it is not a complete solution.

The other method is of course to transform all distances to meters and
plot that together with
coord_equal(ratio=1)
which is the default, so
coord_equal()
is enough. The conversion to meters can be done through projections
inside some geostatistics packages in R (gstat, geoR) or, if you want
to keep things a bit simpler, using a function that takes lat and lon
as input directly. I have found rdist.earth in fields not to be very
precise and have coded one from several sources I found online. It is
attached here. I can guarantee that the results are accurate but,
since it currently uses a loop, it can also be very slow. The way I
use it is:
data$x = geod.dist(refLon, refLat, data$lon, refLat)
data$y = geod.dist(refLon, refLat, refLon, data$lat)
I hope this helps a bit, for now.

Oh and, by the way Hadley, while coord_equal() works it also has the
annoying effect of forcing the plot to be square. The fact that I want
to coordinates to be equal does not mean that the region I want to
plot cannot be a rectangle. I gave you a few illustrated examples with
the behaviour I would expect a while back (email thread "ggplot2,
coord_equal and aspect ratio" started on Fri, Jan 11, 2008 by
jo.ir...@gmail.com), but in case they got lost, look at page 5 of
this file:
http://jo.irisson.com/teaching/villefranche/mapping_and_interpolation.pdf
I would rather have the x axis go from about 7.295 to 7.34, so that I
can easily juxtapose plots such as on page 6 for example. Currently
much of space is taken by useless grid squares that contain no data.

Thanks in advance for your help,

JiHO
---
http://maururu.net
geod_dist.r

hadley wickham

unread,
Dec 6, 2009, 7:20:18 PM12/6/09
to JiHO, Paulo Eduardo Cardoso, ggplot2
> Oh and, by the way Hadley, while coord_equal() works it also has the
> annoying effect of forcing the plot to be square. The fact that I want
> to coordinates to be equal does not mean that the region I want to
> plot cannot be a rectangle. I gave you a few illustrated examples with
> the behaviour I would expect a while back (email thread "ggplot2,
> coord_equal and aspect ratio" started on Fri, Jan 11, 2008 by
> jo.ir...@gmail.com), but in case they got lost, look at page 5 of
> this file:

See
http://github.com/hadley/ggplot2/issues/labels/coord#issue/15

Hadley

--
http://had.co.nz/

JiHO

unread,
Dec 6, 2009, 7:58:38 PM12/6/09
to hadley wickham, Paulo Eduardo Cardoso, ggplot2
On Mon, Dec 7, 2009 at 01:20, hadley wickham <h.wi...@gmail.com> wrote:
> See
> http://github.com/hadley/ggplot2/issues/labels/coord#issue/15

Oh I see you've been using the bug tracker for a few days. Nice. I'll
try to post further issues there then.

Glad to know it has been identified as an issue.

JiHO
---
http://maururu.net
Reply all
Reply to author
Forward
0 new messages