# How to color a tif file in R? [closed]

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

• I'm voting to close this question as off-topic because it belongs on StackOverflow. Feb 2 '16 at 8:17
• 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. Feb 2 '16 at 9:05
• 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. Feb 2 '16 at 16:50

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

library(raster)
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):

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)


(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.)

• Looks like a map of Hungarian postal codes, I bet you'll be fine from a copyright perspective. Feb 4 '16 at 0:14