r - Choropleth world map -
i have read many threads , articles , keep getting errors. trying make choropleth? map of world using data have global terrorism database. want color countries on factor of nkills or number of attacks in country.. don't care @ point. because there many countries data, unreasonable make plots show data.
help appreciated , if did not ask correctly sincerely apologize, learning rules of website go.
my code (so far..)
library(maps) library(ggplot2) map("world") world<- map_data("world") gtd<- data.frame(gtd) names(gtd)<- tolower(names(gtd)) gtd$country_txt<- tolower(rownames(gtd)) demo<- merge(world, gts, sort=false, by="country_txt") in gtd data frame, name countries column "country_txt" thought use error in fix.by(by.x, x) : 'by' must specify uniquely valid column
if work, plot have seen on few websites.. have been working on long , have read many codes/other similar questions/websites/r handbooks etc.. accept incompetent when comes r gladly help.
building on nice work @jlhoward. instead use rworldmap has world map in r , has functions aid joining data map. default map deliberately low resolution create 'cleaner' look. map can customised (see rworldmap documentation) here start :
library(rworldmap) #3 lines @jlhoward gtd <- read.csv("globalterrorismdb_1213dist.csv") gtd.recent <- gtd[gtd$iyear>2009,] gtd.recent <- aggregate(nkill~country_txt,gtd.recent,sum) #join data map gtdmap <- joincountrydata2map( gtd.recent, namejoincolumn="country_txt", joincode="name" ) mapdevice('x11') #create world shaped window #plot map mapcountrydata( gtdmap, namecolumntoplot='nkill', catmethod='fixedwidth', numcats=100 ) 
following comment @hk47, can add points map sized number of casualties.
deaths <- subset(x=gtd, nkill >0) mapbubbles(deaths, namex='longitude', namey='latitude', namezsize='nkill', namezcolour='black', fill=false, addlegend=false, add=true) 
Comments
Post a Comment