0
$\begingroup$

I have a tif file that shows a map. On white background the border of ditricts are drawn with black, nothing else is on the picture. I want to color the districts according to certain values. Is it possible to do that in R? (since the picture doesn't "know" the name of districts in advance I suppose I have to do some manual work but it's ok for me)

UPDATE: the picture is similar to this one: http://www.geoindex.hu/wp-content/uploads/evk_106_20140101.png

$\endgroup$
3
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because it belongs on StackOverflow. $\endgroup$
    – Spacedman
    Feb 2, 2016 at 8:17
  • 3
    $\begingroup$ What map - can you add it to the post? Maybe it's freely available as a shahepfile already? In case you have to get your hands dirty, better use a dedicated tool to polygonize your raster image to a vector file, such as QGIS. The result might - after some cleanup - be fine for a simple choropleth map. If you also need geographical locations, you might want to georeference it. You already find plenty of information on gis.stackexchange.com on all that. $\endgroup$
    – lukeA
    Feb 2, 2016 at 9:05
  • $\begingroup$ Who upvoted this? Note the mouseover note says "This questions shows research effort; it is useful and clear". I don't see any of those apply here. This should be moved to SO or GIS and still needs a lot of work with some basic details. $\endgroup$
    – Spacedman
    Feb 2, 2016 at 16:50

1 Answer 1

2
$\begingroup$

As I said, maybe there is already a public domain vector file that fits your needs, e.g.

library(raster)
map <- getData("GADM", country="HUN", level=2) 
plot(map, col=rainbow(length(map)), border=NA)

Otherwise, try a dedicated tool to polygonize your raster image and save it as a shapefile. E.g. using QGIS (German):

enter image description here

After saving the shapefile, you can load and process it in R:

library(raster)
map <- shapefile("evk_106_20140101.shp")
plot(map, col=rainbow(length(map)), border=NA)

enter image description here

(Side note: I assume it's ok for any copyright owner oto modify and use the image for demonstrational purposes in the above way. If not, drop a comment and I'll delete it.)

$\endgroup$
1
  • 1
    $\begingroup$ Looks like a map of Hungarian postal codes, I bet you'll be fine from a copyright perspective. $\endgroup$ Feb 4, 2016 at 0:14

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