I have a dataset called carcass, which contains occurrences of livestock carcasses in Norway in the last 5 years (each raw corresponds to a single carcass, which has an ID number, along with longitude, latitude and year). I have also a shapefile called regions, a vector file over the different regions in Norway (every region has an ID number as well, specified in the column number_reg).
I managed to plot the map of the regions in R, and to plot the points corresponding to each carcass over the map.
regions<-readShapeSpatial("\\\\homer.uit.no/fma023/Desktop/Filippo Marolla/Datasets/rbd2012_siida.shp") plot(regions) carcass<-readShapePoints("\\\\homer.uit.no/fma023/Desktop/Filippo Marolla/Datasets/carcass_data_edit.shp") plot(carcass, add=T, pch=20, cex=.5, col="red")
Then, I managed to count how many points fall within each district using the over function:
I also managed to plot the temporal trend of carcass occurrences for the entire country:
plot(table(carcass$YEAR), type="o", ylab="Carcass occurrences", main="Temporal trend of carcass occurrences in Norway")
Now I need to plot carcass occurrences over time for every single region, i.e. I want a graph with number of carcasses on y-axis and time (year) on x-axis for region 1, same graph for region 2, same graph for region 3, and so forth.
However, I am in trouble since the over function in R "(...) at the spatial location of object x retrieves the indexes or attributes from spatial object y", therefore in my res object I don't have the column year included (because year is in the carcass dataset, not in the regions dataset).