I'm trying to create a faceted map with two layers using ggplot. One is from a data frame containing lat/lon coordinates, created from a CSV:
head(poijoin)
NAME LAT LNG level1
ATM Bank Of America ATM @ WHC 38.92825 -77.01517 ShopService
ATM Bank Of America ATM 38.90577 -77.03654 ShopService
ATM Bank of America 38.91512 -77.02184 ShopService
ATM USAA ATM @CVS 38.91343 -77.03590 ShopService
ATM Bank of America ATM 38.95511 -77.02473 ShopService
The other one is coming from a street network shape file, turned into a dataframe using fortify:
head(streets_df)
LNG LAT order piece id group
1 -77.02704 38.90253 1 1 0 0.1
2 -77.02704 38.90303 2 1 0 0.1
3 -77.02704 38.90303 3 1 0 0.1
4 -77.02704 38.90304 4 1 0 0.1
5 -77.02704 38.90326 5 1 0 0.1
Plotting them individually works just fine, so does overlaying them:
ggplot() +
geom_point(data = poijoin, aes(x = poijoin$LNG, y = poijoin$LAT)) +
geom_path(data = streets_df, aes(x = LNG, y = LAT, group = group))
(Not very pretty, I know, but I'm trying to stick to the basic parts of the code here.)
I can also facet the points layer without problems:
ggplot() +
geom_point(data = poijoin, aes(x = poijoin$LNG, y = poijoin$LAT)) +
facet_wrap(~ poijoin$level1, nrow=3)
However, if I want to add the streets as a base map to each facet, I'm stuck. This:
ggplot() +
geom_point(data = poijoin, aes(x = poijoin$LNG, y = poijoin$LAT, color = poijoin$level1)) +
geom_path(data = streets_df, aes(x = LNG, y = LAT, group = group)) +
facet_wrap(~ poijoin$level1, nrow=3)
Gives me:
Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(8L, 8L, 8L, 8L, :
replacement has 20983 rows, data has 200205
I'm sure the error comes up because the two data frames have a different number of elements (20983 points and 200205 streets), but I still don't get what I'm doing wrong. Any pointers appreciated!



~ poijoin$level1- hrbrmstr