I have a data frame with coordinates of tweets such as:
library(ggplot2)
df <- data.frame(long = c(-58.1, -58.2, -58.3, -58.4, -58.5, -55),
lat = c(-34.1, -34.2, -34.3, -34.4, -34.5, -25))
I would like to plot the Metropolitan area of buenos aires, known as AMBA. It's defined by the area: longitud: (-58, -59) latitude: (-34, -35)
I have a row in my data frame that's outside the AMBA area. (important for question (2))
con <- url("http://gadm.org/data/rda/ARG_adm2.RData")
print(load(con))
close(con)
ggmap <- fortify(gadm, region = "NAME_2")
lim <- data.frame(lon = c(-59, -58), lat = c(-35, -34))
ggplot(data=ggmap, aes(x=long, y=lat)) +
scale_x_continuous(limits = c(-59,-58)) +
scale_y_continuous(limits = c(-35,-34)) +
geom_polygon(data = ggmap, fill = "grey80", aes(group=group)) +
geom_path(color="white",aes(group=group)) +
geom_point(data = df, aes(x = lon, y = lat, colour = "red"), alpha = 30/100)
Try coord_map
instead of scale_x_continuous
/scale_y_continuous
.
Setting limits on the coordinate system will zoom the plot (like you're looking at it with a magnifying glass), and will not change the underlying data like setting limits on a scale will.
ggplot(data=ggmap, aes(x=long, y=lat)) +
geom_polygon(data=ggmap, fill="grey80", aes(group=group)) +
geom_path(color="white",aes(group=group)) +
geom_point(data=df, aes(x=long, y=lat), colour="red", alpha=30/100) +
coord_map(xlim=-c(59, 58), ylim=-c(35,34))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With