R version 3.2.1
I'm following this article on how to create Heat Maps and downloaded the required files (just need help with the logic)
This works
setwd("D:/GIS/london")
library(maptools)
library(ggplot2)
library(gpclib)
sport <- readShapeLines("london_sport.shp")
When I run
names(sport)
I get normal output, i.e.
[1] "ons_label" "name" "Partic_Per" "Pop_2001"
And when I print sport
print(sport)
I get this (showing first 6 lines)
geometry ons_label name Partic_Per Pop_2001
0 MULTILINESTRING((541177.7 173555.7 ...)) 00AF Bromley 21.7 295535
1 MULTILINESTRING((522957.6 178071.3 ...)) 00BD Richmond upon Thames 26.6 172330
2 MULTILINESTRING((505114.9 184625.1 ...)) 00AS Hillingdon 21.5 243006
3 MULTILINESTRING((552108.3 194151.8 ...)) 00AR Havering 17.9 224262
4 MULTILINESTRING((519370.8 163657.4 ...)) 00AX Kingston upon Thames 24.4 147271
5 MULTILINESTRING((525554.3 166815.8 ...)) 00BF Sutton 19.3 179767
6 MULTILINESTRING((513062.8 178187.2 ...)) 00AT Hounslow 16.9 212352
So far everything looks normal. I understand the next few lines, to create plot points
p <- ggplot(sport@data, aes(Partic_Per, Pop_2001))
p + geom_point(aes(color="Partic_Per", size = "Pop_2001")) + geom_text(size=2, aes(label=name))
gpclibPermit()
Then we make the shape file (sport) into a data frame
sport_geom <- fortify(sport, region="ons_label")
And when I execute head(sport_geom)
I get
long lat order piece group id
1 541177.7 173555.7 1 1 0.1 0
2 541872.2 173305.8 2 1 0.1 0
3 543441.5 171429.9 3 1 0.1 0
4 544361.6 172379.2 4 1 0.1 0
5 546662.4 170451.9 5 1 0.1 0
6 548187.1 170582.3 6 1 0.1 0
Then the command to merge data, where the problem arises
sport_geom <- merge (sport_geom, sport@data, by.x = "id", by.y = "ons_label")
When I go according to the document and print by.
, the only values that pop up are by.data.frame
and by.default
And when I execute head(sport_geom)
, the data is blank!!!
[1] id long lat order piece group
name Partic_Per Pop_2001 <0 rows> (or 0-length row.names)
What am I missing and how to troubleshoot this?
Perhaps this is an error in the document (this is the simplest tutorial I can find on Heat Maps), because I was troubleshooting another error for the past hour.
Please help!!!!!! I know it's long, but it's the best I could do to explain the issue and possibly reproduce it.
If you need links to download the stuff, I'll get it for you.