[R-sig-Geo] overlay 1D graph on a map or map image: van Langren data
Michael Friendly
friendly at yorku.ca
Wed Dec 3 16:44:00 CET 2008
hadley wickham wrote:
>
> Here's a quick start using ggplot2 - one trick to make the map look
> nicer is to use a bigger range when calling map, and then adjust the
> limits of the plot to zoom in on the region of interest.
>
> library(maps)
> library(ggplot2)
>
> langren <- read.csv("http://euclid.psych.yorku.ca/SCS/Gallery/Private/langrens.csv",
> header=TRUE)
>
> bbox <- c( 38.186, -9.184,
> 43.692, 28.674 )
> bbox <- matrix(bbox, 2, 2, byrow=TRUE)
>
> borders <- as.data.frame(map("world", plot = F,
> xlim = expand_range(bbox[,2], 0.2),
> ylim = expand_range(bbox[,1], 0.2))[c("x", "y")])
>
> data(world.cities)
> cities <- subset(world.cities,
> name %in% c("Rome", "Toledo") & country.etc %in% c("Spain", "Italy"))
>
> ggplot(langren, aes(long, lat)) +
> geom_path(aes(x, y), borders, colour = "grey60") +
> geom_point(y = 40) +
> geom_text(aes(label = name), y = 40.1, angle = 90, hjust = 0, size = 3) +
> geom_point(data = cities, colour = "red", size = 2) +
> coord_cartesian(xlim=bbox[,2], ylim=bbox[,1])
>
>
Thanks very much, Hadley. However, it doesn't work for me, using
ggplot2_0.7, even when adding
langren$lat <- 39.68
> ggplot(langren, aes(long, lat)) +
+ geom_path(aes(x, y), borders, colour = "grey60") +
+ geom_point(y = 40) +
+ geom_text(aes(label = name), y = 40.1, angle = 90, hjust = 0, size =
3) +
+ geom_point(data = cities, colour = "red", size = 2) +
+ coord_cartesian(xlim=bbox[,2], ylim=bbox[,1])
Error in get("new", env = CoordCartesian, inherits =
TRUE)(CoordCartesian, :
unused argument(s) (xlim = c(-9.184, 28.674), ylim = c(38.186, 43.692))
Eliminating the last line (coord_caertesian) gives a different error,
and just the first gives
> ggplot(langren, aes(long, lat))
Error: No layers in plot
> sessionInfo()
R version 2.8.0 (2008-10-20)
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
[1] splines grid stats graphics grDevices utils
datasets methods
[9] base
other attached packages:
[1] ggplot2_0.7 MASS_7.2-44 RColorBrewer_1.0-2
proto_0.3-8
[5] reshape_0.8.2 plyr_0.1.3 rimage_0.5-7
foreign_0.8-29
[9] maps_2.0-40
...
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
More information about the R-sig-Geo
mailing list