1

I'm trying to plot a map of Toronto with ward boundaries and geocoded data on events over years. But the layout is such that I end up with mostly wasted space in the map. To increase resolution for the data I would prefer to rotate all the data about 12-15 degrees clockwise to make the top boundary approximately horizontal and clip the map to a bit more than the city boundary shown below.

enter image description here

The ward boundaries come from http://www1.toronto.ca/City_Of_Toronto/Information_Technology/Open_Data/Data_Sets/Assets/Files/wards_may2010_wgs84.zip and are read in using rgdal:

dir <- "C:/Dropbox/Documents/consulting/Abigail"
folder <- "wards_may2010_wgs84"
library(rgdal)
wards <- readOGR(paste0(dir,folder), layer="icitw_wgs84")
plot(wards, col="gray95")

ward boundaries

I get the map for my main plot with get_map:

library(ggmap)
map <- get_map("Toronto", zoom=10)
p <- ggmap(map)
# convert wards to a data.frame for use with ggplot2/ggmap and plot
wards.df <- fortify(wards)
p +
    geom_point(data = section37, aes(x = long, y = lat, group = Ward), size=0.7, color="red") +
    geom_polygon(data=wards.df, aes(x = long, y = lat, group=group), 
                 color="blue", alpha=.1)

I'm fairly new to mapping applications in R, so could use some help with this task.

1

You can rotate the coordinates of an SP object using elide from maptools, but you'll lose any true geographic location reference. You also won't be able to overlay on map tiles since they are fixed at that alignment.

Example using scot_BNG from readOGR:

> plot(scot_BNG)
> plot(elide(scot_BNG, rotate=-45))

enter image description here

Alternatively use an oblique mercator projection roughly centred on your area of interest to project your entire map. Here I've used:

+proj=omerc +lat_0=43 +gamma=0 +lonc=-80 +alpha=-17 +k_0=1 +x_0=0 +y_0=0

to rotate Toronto in QGIS. Note how the background image is rotated and possibly skewed a bit, and poor quality due to resampling onto the new grid.

enter image description here

I'm not sure if ggmap supports arbitrary projections, but if it does you could try this in R.

  • Thanks; I see that maptools::elide() works with my SP object, as in plot(elide(wards, rotate=15), col="gray95"), but not with the ggmap object. – user101089 May 25 '16 at 0:41
  • Correct. If you want to rotate a google maps image then it will look rubbish since the labels will all be at an angle and the image will have been interpolated. You may as well just tilt your head 15 degrees. If you want nicely rotated map backgrounds you need a vector source. – Spacedman May 25 '16 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.