Last active
January 4, 2017 16:17
-
-
Save northernjamie/ec23c02f11b5df6dd133cc597f41d9d0 to your computer and use it in GitHub Desktop.
Pulls in the SPARQL query from Gist ScotDstoreRUnion into R and makes a correlation plot bubble type thing
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) | |
endpoint<-"http://statistics.gov.scot/sparql" | |
query <- "PREFIX qb: <http://purl.org/linked-data/cube#> | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | |
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/concept#> | |
PREFIX data: <http://statistics.gov.scot/data/> | |
PREFIX sdmxd: <http://purl.org/linked-data/sdmx/2009/dimension#> | |
PREFIX mp: <http://statistics.gov.scot/def/measure-properties/> | |
PREFIX stat: <http://statistics.data.gov.uk/def/statistical-entity#> | |
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | |
SELECT ?areaname ?indicatorlabel ?yearname ?value | |
WHERE { | |
{?indicator qb:dataSet data:earnings-paygap ; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2010> . | |
data:earnings-paygap rdfs:label ?indicatorlabel} | |
UNION | |
{?indicator qb:dataSet data:drug-related-discharge ; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2015-2016> . | |
data:drug-related-discharge rdfs:label ?indicatorlabel} | |
UNION | |
{?indicator qb:dataSet data:age-at-first-birth ; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/gregorian-interval/2005-01-01T00:00:00/P2Y> ; | |
<http://statistics.gov.scot/def/dimension/age> <http://statistics.gov.scot/def/concept/age/19-and-under> . | |
data:age-at-first-birth rdfs:label ?indicatorlabel} | |
UNION | |
{?indicator qb:dataSet data:dtp-pol-hib-uptake-by-24-months ; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2015> ; | |
<http://statistics.gov.scot/def/dimension/indicator(dtpPolHibUptake)> <http://statistics.gov.scot/def/concept/indicator-dtp-pol-hib-uptake/percentage-vaccinated-against-dtp/pol/hib-by-24-months> . | |
data:dtp-pol-hib-uptake-by-24-months rdfs:label ?indicatorlabel} | |
UNION | |
{?indicator qb:dataSet data:crime-clear-up-rates; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/year/2012> ; | |
<http://statistics.gov.scot/def/dimension/crimeOrOffence> <http://statistics.gov.scot/def/concept/crime-or-offence/all-crime> . | |
data:crime-clear-up-rates rdfs:label ?indicatorlabel} | |
UNION | |
{?indicator qb:dataSet data:alcohol-related-discharge ; | |
sdmxd:refPeriod <http://reference.data.gov.uk/id/government-year/2015-2016> . | |
data:alcohol-related-discharge rdfs:label ?indicatorlabel} . | |
?indicator sdmxd:refArea ?area ; | |
sdmxd:refPeriod ?year ; | |
mp:ratio ?value . | |
?year rdfs:label ?yearname . | |
?area stat:code <http://statistics.gov.scot/id/statistical-entity/S12> ; | |
rdfs:label ?areaname ; | |
skos:notation ?areacode | |
}" | |
qddata <- SPARQL(endpoint,query) | |
df<-qddata$results | |
library(ggplot2) | |
library(reshape2) | |
dfmatrix <- acast(df, areaname ~ indicatorlabel, value.var='value',fun.aggregate=sum, margins=FALSE) | |
corrmatrix <- cor(dfmatrix) | |
library(corrplot) | |
corrchart <- corrplot(corrmatrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment