Last active
May 8, 2018 20:17
-
-
Save allenday/546d06f2a1c5cecf2ef9 to your computer and use it in GitHub Desktop.
Plot nomadlist.io score as a function of cost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nomad=fromJSON(paste(scan("http://nomadlist.io/api/v1", what="c",sep=""),collapse="")) | |
nomad.has=function(){names(nomad[3]$cities[[1]])} | |
nomad.get=function(y){unlist(lapply(nomad[3]$cities,function(x){x[[y]]}))} | |
nomadCost = as.numeric(nomadvar("nomadCost")[names(nomadvar("nomadCost"))=="USD"]) | |
nomadScore = as.numeric(nomadvar("nomadScore")) | |
plot(nomadCost, nomadScore) | |
cost.vs.score = lm(nomadScore ~ nomadCost) | |
abline(cost.vs.score,col="red") | |
dat = cbind(as.numeric(nomad.get("lowendHotelCostDaily")[names(nomad.get("lowendHotelCostDaily"))=="USD"])) | |
dat = cbind(dat,as.numeric(nomad.get("wifiAvailability"))) | |
dat = cbind(dat,as.numeric(nomad.get("localEnglishSpeaking"))) | |
dat = cbind(dat,as.numeric(nomad.get("lbgtFriendly"))) | |
dat = cbind(dat,as.numeric(nomad.get("coworkingCost")[names(nomad.get("coworkingCost"))=="USD"])) | |
dat = cbind(dat,as.numeric(nomad.get("basicMealCost")[names(nomad.get("basicMealCost"))=="USD"])) | |
dat = cbind(dat,as.numeric(nomad.get("safetyLevel"))) | |
dat = cbind(dat,as.numeric(nomad.get("hostelCostDaily")[names(nomad.get("hostelCostDaily"))=="USD"])) | |
dat = cbind(dat,as.numeric(nomad.get("apartmentCostDaily")[names(nomad.get("apartmentCostDaily"))=="USD"])) | |
dat = cbind(dat,as.numeric(nomad.get("internetSpeed"))) | |
dat = cbind(dat,as.numeric(nomad.get("globalPeaceIndex"))) | |
dat = cbind(dat,as.numeric(nomad.get("friendlyToForeigners"))) | |
dat = cbind(dat,as.numeric(nomad.get("qualityOfNightlife"))) | |
dat = cbind(dat,as.numeric(nomad.get("coffeePlaceWithWifiDensity"))) | |
colnames(dat) = c("lowendHotelCostDaily", | |
"wifiAvailability", | |
"localEnglishSpeaking", | |
"lbgtFriendly", | |
"coworkingCost", | |
"basicMealCost", | |
"safetyLevel", | |
"hostelCostDaily", | |
"apartmentCostDaily", | |
"internetSpeed", | |
"globalPeaceIndex", | |
"friendlyToForeigners", | |
"qualityOfNightlife", | |
"coffeePlaceWithWifiDensity" | |
) | |
rownames(dat) = nomad.get("name") | |
#allen | |
ad.importance = c( -0.1, 3, 5, 0.1, -3, -7, 7, -0.1, -10, 4, 1, 3, 2, 0.1) | |
#erik | |
eo.importance = c( -10, 2, 2, 0.1, -7, -7, 5, -0.1, -10, 5, 1, 1, 3, 2) | |
#allen heatmap | |
heatmap(t( apply(dat, 1, function(x) { x * ad.importance }) ), scale="col") | |
#erik heatmap | |
heatmap(t( apply(dat, 1, function(x) { x * eo.importance }) ), scale="col") | |
#random viz | |
rn.importance = abs(rnorm(14, sd=4)) * c(-1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1) | |
heatmap(t( apply(dat, 1, function(x) { x * rn.importance }) ), scale="col") | |
#remove crap | |
dat[ is.na(dat) ] = 0 | |
ad.score = apply( t(apply(dat, 1, function(x) { x * ad.importance }) ), 1, function(x){sum(x,na.rm=F)} ) | |
eo.score = apply( t(apply(dat, 1, function(x) { x * eo.importance }) ), 1, function(x){sum(x,na.rm=F)} ) | |
rn.score = apply( t(apply(dat, 1, function(x) { x * rn.importance }) ), 1, function(x){sum(x,na.rm=F)} ) | |
plot(ad.score, eo.score, pch=".") | |
text(ad.score, eo.score, names(ad.score), cex=0.5) | |
plot(ad.score, rn.score, pch=".") | |
text(ad.score, rn.score, names(ad.score), cex=0.5) | |
#names(sort(rank(z))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment