[英]R ggplot2 worldmap. breaks in legend
我正在嘗試在R中使用ggplot2生成世界地圖。它應該是基於國家/地區的熱圖。 我正在處理的數據來自twitter,我想顯示這些tweet的來源。 有兩個問題:
綜合數據
map_data("world")
給我一張20年以上的地圖(蘇聯)。
map_data("world2")
似乎損壞了。 或有一些訂購問題,但我不知道如何解決。
http://schloegl.net/supersambo/world2.pdf
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.