Hi,
I’m trying to draw a map using grom_polygon just to have a land mask;
library(ggplot2)
library(maps)
world_map <- map_data("world")
p <- ggplot(aes(x = long, y = lat), data = world_map) +
geom_polygon(aes(group = group))
p
The problem appears if the extent of the map is restricted (for instance, to greenland)
p + ylim(60, 70) + xlim(-60, -20) + coord_map()
Any idea of what I’m doing wrong? Thanks in advance,
fernando
Hmmm, what you really want to be able to do is set x and y limits on
coord_map, but that currently isn't possible. I'll add it to my to do
list: http://github.com/hadley/ggplot2/issues/#issue/62
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
>
No, that is what I was addressing. When you set the limits of a scale
it throws away all the data outside those limits. When you see the
limits for a coordinate system it zooms in on that area.
Hadley
On Fri, Jan 8, 2010 at 3:30 AM, fernando <fgta...@gmail.com> wrote:
> Hi Hadley,
>
> Sorry if this is a misunderstanding, but I think that my point was not to be
> able to set the limits of the plot in coord_map, but to don't lose part of
> the polygons if the limits of a plot are restricted. It seems that the
> polygons are drawn using only the data points within the limits of the plot,
> and in this way the shape is altered if you restrict the extent of the plot.
> I hope that the example bellow illustrates better my point.
>
> I take the occasion to thank you, ggplot and plyr are quite impressive tools
>
> Best regards,
> Fernando
>
>
> PS:
>
> library(ggplot2)
>
> x <- c(-0.5, 0, 0.5, 0)
> y <- c(0, -1, 0, 1)
> x11()
> qplot(x, y, geom = "polygon")
> x11()
> qplot(x, y, geom = "polygon") + ylim(-1, 0.8)
> # will not appear as might be expected; the diamond is now a triangle
>
>
> # sessionInfo()
> # R version 2.10.1 (2009-12-14)
> # i386-pc-mingw32
> #
> # locale:
> # [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
> # [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
> # [5] LC_TIME=Spanish_Spain.1252
> #
> # attached base packages:
> # [1] grid stats graphics grDevices utils datasets methods
> # [8] base
> #
> # other attached packages:
> # [1] ggplot2_0.8.5 digest_0.4.2 reshape_0.8.3 plyr_0.1.9 proto_0.3-8
>
>
>
>
> -----Mensaje original-----
> De: hadley wickham [mailto:h.wi...@gmail.com]
> Enviado el: miércoles, 06 de enero de 2010 22:46
> Para: fernando
> CC: ggp...@googlegroups.com
> Asunto: Re: polygon shape distorted; geom_polygon, ylim, xlim
Could you add the same thing for coord_equal to that to do list? It
seems to have the same issue and coord_equal can likewise be used for
similar map plots with certain local coordinate systems.
-- Osmo
The reason I've never done that for coord_equal is that I haven't
figure out how to reconcile the three constraints (xlim, ylim and
ratio) if they're different. Also, if you're setting xlim and ylim,
then you can just use coord_cartesian and set the aspect ratio
yourself.
Hadley
What do you mean? How do i set the aspect ratio without coord_equal?
-- Osmo