Skip to content

Instantly share code, notes, and snippets.

View northernjamie's full-sized avatar

Jamie Whyte northernjamie

  • Propolis Open Data Factory
  • Manchester, UK
View GitHub Profile
@northernjamie
northernjamie / SPARQLScotDatastoreDrug1.sparql
Last active November 20, 2016 10:48
SPARQL Scottish Datastore Drug Related Discharge
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 ?areacode ?areaname ?nratiodrug ?yearname
WHERE {
library(“SPARQL”, lib.loc=”/Library/Frameworks/R.framework/Versions/3.2/Resources/library”)
endpoint <- ‘http://statistics.gov.scot/sparql'
queryalc <- ‘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#>
dfmerged <- merge(dfalc,dfdrug,by = “areaname”)
ggplot(data = dfdrug, aes(x=reorder(areaname, -nratiodrug), y=nratiodrug, fill=areaname)) + theme_bw() + geom_bar(stat='identity') + theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + ggtitle('Drug-related Hospital Discharges 2012–2013 (Rate per 10,000 people)') + labs(x='Council Area', y='Rate per 100,000 people') + theme(legend.position='none')
cor.test(dfmerged$nratioalcohol,dfmerged$nratiodrug)
@northernjamie
northernjamie / ScotDstoreRDrawScatterDrugAlc.r
Last active November 18, 2016 22:20
Scatterplot in R for 2nd Swirrl Article
ggplot(dfmerged, aes(x=nratiodrug, y=nratioalcohol,label=areaname)) + geom_point(shape=21, size=6, color="blue",fill="red", alpha=0.3) + geom_text(data=subset(dfmerged, nratioalcohol > 1300)) + stat_smooth(method = "lm", col = "red") + ggtitle('Scatterplot Showing Drug and Alcohol-related Hospital Admissions, 2012–2013') + labs(x='Drug-related discharges, per 100,000 people', y='Alcohol-related discharges, per 100,000 people') + theme_bw()
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/concept#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
##### Very rough!!!!
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#>
@northernjamie
northernjamie / ScotDstoreRUnionCorr.sparql
Created January 4, 2017 11:52
Big UNION SPARQL to combine different indicators at Local Authority level to create a correlation matrix in R
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
@northernjamie
northernjamie / ScotDstoreRDrawCorrelationMatrix.r
Last active January 4, 2017 16:17
Pulls in the SPARQL query from Gist ScotDstoreRUnion into R and makes a correlation plot bubble type thing
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#>