Mapping world + ggplot2

77 views
Skip to first unread message

Aurelie Cosandey Godin

unread,
Mar 21, 2012, 9:37:29 AM3/21/12
to ggplot
Hi all,

I'm trying to plot the world in ggplot2.
I've followed Hadley's instructions: http://had.co.nz/ggplot/examples/maps.html

library(maps)
library(ggplot2)
reg <- as.data.frame(map("world", plot = FALSE)[c("x", "y")])
qplot(x, y, data = reg, type = "path")

But I do get really thick lines...? Anyone know how I can fix this? Or have a better way to print a world map in ggplot2.
Thank you very much in advance,

Aurelie





Ben Bond-Lamberty

unread,
Mar 21, 2012, 9:43:31 AM3/21/12
to ggplot
qplot(x, y, data = reg, type = "path",size=I(.5))    # or whatever 'size' you want; see ?geom_path

Ben


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Rplot.png

Aurelie Cosandey Godin

unread,
Mar 21, 2012, 10:04:47 AM3/21/12
to Ben Bond-Lamberty, ggplot
Thank you Ben,
Actually just tweaking the code did the trick!

p <- ggplot(reg, aes(x, y))
p + geom_path()

Best,
Aurelie


On 2012-03-21, at 10:43 AM, Ben Bond-Lamberty wrote:

qplot(x, y, data = reg, type = "path",size=I(.5))    # or whatever 'size' you want; see ?geom_path

Ben
On Wed, Mar 21, 2012 at 9:37 AM, Aurelie Cosandey Godin <God...@dal.ca> wrote:
Hi all,

I'm trying to plot the world in ggplot2.
I've followed Hadley's instructions: http://had.co.nz/ggplot/examples/maps.html

library(maps)
library(ggplot2)
reg <- as.data.frame(map("world", plot = FALSE)[c("x", "y")])
qplot(x, y, data = reg, type = "path")

But I do get really thick lines...? Anyone know how I can fix this? Or have a better way to print a world map in ggplot2.
Thank you very much in advance,

Aurelie


<Rplot.png>




--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Jean-Olivier Irisson

unread,
Mar 21, 2012, 12:26:09 PM3/21/12
to Ben Bond-Lamberty, ggplot
On 2012-Mar-21, at 14:43 , Ben Bond-Lamberty wrote:
>
> qplot(x, y, data = reg, type = "path",size=I(.5)) # or whatever 'size' you want; see ?geom_path

No the problem comes from the syntax itself, not the size argument. The type of geom is specified with the `geom` argument, not the `type` argument. So it should be:

library(maps)
library(ggplot2)
reg <- as.data.frame(map("world", plot = FALSE)[c("x", "y")])

qplot(x, y, data = reg, geom = "path")

In the previous example you were drawing points, which looked bigger.

The last line is exactly equivalent to what you did later:

ggplot(reg, aes(x, y)) + geom_path()

Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/

Reply all
Reply to author
Forward
0 new messages