0

I've been trying to make a map of plots within Quebec but I've been struggling.

I have some data which is in this format:

| Plot id | latitude | longitude | Ecozone |

I need to plot these points onto a map of just Quebec (8277 points) and have been googling trying to find out how to do this. Tutorials often use whole countries but I only need to show Quebec, not the rest of Canada. I would each plot to be plotted on the map & they would be coloured relating to the ecozone (ecozones 3-6) in different colours.

So my map would need to look something like this but with all my plots, no labels needed or anything:

Basic version

I can't figure out how to get a plotted map of just Quebec using the map_data plugins etc. I will be able to put the points on after just struggling to get the outline of quebec plotted.

Zequo
  • 13
  • 2
  • 1
    what have you tried? Do you have a shapefile for Quebec or a definition of its boundaries, or is this part of what you're struggling with? – Ben Bolker Mar 04 '22 at 23:18
  • starting point? https://stackoverflow.com/questions/60192799/map-data-for-canadian-provinces-in-r – Ben Bolker Mar 04 '22 at 23:24
  • I have tried following that already and it wasn't working for me, very confusing. I have tried using this GADM way but couldn't get it to work, also tried the map_data function but couldn't get only quebec for that. Not tried a shapefile yet because when I downloaded the file I couldn't get it transferred into R. Still no luck – Zequo Mar 05 '22 at 02:23
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 05 '22 at 12:06
  • Theres not really any code to go off. The problem I'm having is getting the map of only Quebec, I can figure out how to add my plot data I'm pretty sure but I'm just stuck on getting this base quebec outline plotted in R – Zequo Mar 05 '22 at 13:23

1 Answers1

0

Maybe this will help you get going.

Here, data is pulled using getData for Canada. Then, you can subset for just Québec if you'd like.

I created a data.frame of points to plot, using Québec City and Montreal as examples.

Then, you can plot the province and add your points.

library(ggplot2)
library(raster)

canada <- getData("GADM", country = "CAN", level = 1)

quebec <- canada[canada$NAME_1 == "Québec", ]

my_points <- data.frame(
  id = 1:2,
  lat = c(46.8139, 45.5017),
  long = c(-70.2080, -73.5673),
  ecozone = factor(3:4)
)

ggplot(quebec, aes(x = long, y = lat)) +
  geom_path(aes(group = group)) +
  geom_point(data = my_points, aes(x = long, y = lat, color = ecozone), size = 5) +
  coord_map() +
  theme_bw()

Map

Québec map with points added

Ben
  • 28,684
  • 5
  • 23
  • 45