I thought R would be good for this... but am a complete novice at it. I have a set of UK Postcodes (e.g. 'CB2 8UR') and a separate table that maps each postcode to an OS grid coordinate. Both start as CSV:
file1:
"pcd"
"CB2 8UR"
"TE3 5LJ"
file2:
"pcd","col2","col3","oseast1m","osnrth1m","col6",...
...
"CB2 8UR","?","?",9823,2034,"?"
...
The real file1 has a thousand or so entries, and the real file2 has several hundred thousand (and about 20 columns). The only point of file2 here is to convert the postcode to a UK OS grid coordinate. At the moment, I think I can treat the coords as being on a 2d plane.
The task is to get a map with the 'centre of mass' of each postcode marked together with a heatmap representation of the postcodes.
I did manage to plot file2 data (i.e. all uk postcodes) as bins using qplot() + stat_bin2d():
m <- qplot(xlab="Longitude",ylab="Latitude",main="Postcode heatmap",geom="blank",x=pcd$oseast1m,y=pcd$osnrth1m,data=pcd) + stat_bin2d(bins =200,aes(fill = log1p(..count..)))
where pcd is a data.frame read from file2.
So:
How can I merge file1 and file to map just the codes in file1 but using the coords in file2?
How can I calculate and add a marker for the centre of mass?
If I wanted to mark some postcodes 'special' so their 'mass' was higher than normal, would that be simple to do?
Many thanks for your help.