Last active
December 7, 2015 14:51
-
-
Save andrawaag/99930b2fec3a56ae60a6 to your computer and use it in GitHub Desktop.
Get a spatial map in R on Number of cases of Tuberculosis 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:Q12204 wdt:P699 ?doid ; # P699 Disease ontology ID | |
p:P1603 ?prevalencewithProvenance . # P1193 prevalence | |
?prevalencewithProvenance 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 Tuberculosis added @SWAT4LS tutorial") | |
View(getMap()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment