[R] passing xlim to coord_map in ggplot2

Ista Zahn istazahn at gmail.com
Wed Mar 21 04:03:32 CET 2012


Hi Zack,

It would help a lot if you can give a reproducible example that
generates the error.

Best,
Ista

On Tue, Mar 20, 2012 at 3:05 PM, z2.0 <zack.abrahamson at gmail.com> wrote:
> This works:
> michigan <- map_data('county', 'michigan')
> mich_points <- data.frame(x = rnorm(n = 200, median(michigan[,1]), 0.75), y
> = rnorm(n = 200, median(michigan[,2]), 0.75))
> ggplot() + geom_path(aes(long, lat, group = group), data = michigan) +
> geom_point(aes(x, y), data = mich_points) + coord_map('gilbert', xlim =
> c(-86, -84))
>
> This generates the following error:
> *Error in unit(x, default.units) : 'x' and 'units' must have length > 0*
> #Where tank_trunc is a data.frame with two columns, 'lon' and 'lat'
> containing point coordinates in storage mode 'double'.
> michigan_map.df <- map_data('county', 'michigan')
> ggplot() + geom_point(aes(lon, lat), data = tank_trunc, na.rm = T) +
> geom_path(aes(long, lat, group = group), data = michigan_map.df) +
> coord_map('gilbert', xlim = c(-88, -82))



More information about the R-help mailing list