Created
December 7, 2015 14:54
-
-
Save andrawaag/0e0a1be13b75480206b4 to your computer and use it in GitHub Desktop.
Get a spatial map in R on Number of cases of Malaria in Wikidata added the SWAT4LS tutorial
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
library(SPARQL) | |
library(ggplot2) | |
library(rworldmap) | |
wdqs <- "https://query.wikidata.org/bigdata/namespace/wdq/sparql" | |
query <- "PREFIX wd: <http://www.wikidata.org/entity/> | |
PREFIX wdt: <http://www.wikidata.org/prop/direct/> | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | |
PREFIX p: <http://www.wikidata.org/prop/> | |
PREFIX v: <http://www.wikidata.org/prop/statement/> | |
PREFIX qualifier: <http://www.wikidata.org/prop/qualifier/> | |
PREFIX statement: <http://www.wikidata.org/prop/statement/> | |
SELECT DISTINCT ?countryLabel ?ISO3Code ?latlon ?prevalence ?year WHERE { | |
wd:Q12156 wdt:P699 ?doid ; # P699 Disease ontology ID | |
p:P1603 ?noc . # P1193 prevalence | |
?noc qualifier:P17 ?country ; | |
qualifier:P585 ?year ; | |
statement:P1603 ?prevalence . # P17 country | |
?country wdt:P625 ?latlon ; | |
rdfs:label ?countryLabel ; | |
wdt:P298 ?ISO3Code ; | |
wdt:P297 ?ISOCode . | |
FILTER (lang(?countryLabel) = \"en\") | |
}" | |
results <- SPARQL(wdqs, query) | |
resultMatrix <- as.matrix(results$results) | |
View(resultMatrix) | |
sPDF <- joinCountryData2Map(results$results, joinCode = "ISO3", nameJoinColumn = "ISO3Code") | |
mapCountryData(sPDF, nameColumnToPlot="prevalence", oceanCol="lightblue", missingCountryCol="white", mapTitle="Number of cases on Malaria added @SWAT4LS tutorial") | |
View(getMap()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment