Rでggplot2を使用して世界地図を作成しようとしています。これは、国ベースのヒートマップである必要があります。私が取り組んでいるデータはツイッターからのものであり、ツイートがどこから来ているのかを示したいと思います。2つの問題があります:
統合データ
map_data("world")
20年前の地図(ソ連)をくれます。
map_data("world2")
破損しているようです。または、注文の問題がありますが、解決方法がわかりません。
http://schloegl.net/supersambo/world2.pdf
- カラーブレイクを変更したいのですが、アクセス方法がわかりません。読みやすい国はブラジルだけなので、休憩を編集して、ツイート数が1000未満の国の違いを示すことが重要です。
http://schloegl.net/supersambo/world.pdf
これが私のコードです
WD <- getwd()
if (!is.null(WD)) setwd(WD)
library(maps)
library(plyr)
library(ggplot2)
twitter=read.csv("/Users/stephanschloegl/Studium/Diplomarbeit/rawData/c_userInfo/c_userInfo.csv",header=TRUE,check.names=FALSE,sep=";")
#read geodata
cities=read.csv("GeoWorldMap/cities.txt",header=TRUE,check.names=FALSE,sep=",")
countries=read.csv("GeoWorldMap/countries.txt",header=TRUE,check.names=FALSE,sep=",")
#find countries for twitter$timezone
lista <- twitter$time_zone
country_ids <- cities$CountryID[match(lista,cities$City)]
country <- countries$Country[match(country_ids,countries$CountryId)]
#FREQENCIES
frequencies <- as.data.frame(table(country))
names(frequencies) <- c("region","freq")
#change 0's to NA
frequencies$freq[frequencies$freq==0] <- NA
#load world data
world <- map_data("world2")
#Delete Antarctica
world <- subset(world,region!="Antarctica")
#merge twitterdata and geodata
world$tweets <- frequencies$freq[match(world$region,frequencies$region,nomatch=NA)]
map <- qplot(long, lat, data = world, group = group,fill=tweets,geom ="polygon",ylab="",xlab="")
#this does'nt work
map + scale_colour_hue(name="Number of\nTweets",breaks=levels(c(10,20,100,200,1000)))
map