Skip to content

Instantly share code, notes, and snippets.

View tts's full-sized avatar

Tuija Sonkkila tts

View GitHub Profile
library(tidyverse)
sparql_endpoint <- "http://dbpedia.org/sparql"
# Query example from https://medium.com/virtuoso-blog/dbpedia-basic-queries-bc1ac172cc09
q <- "
SELECT ?athlete ?cityName
WHERE
{
?athlete rdfs:label 'Cristiano Ronaldo'@en ;
@tts
tts / gist:9c953059d4686c634d5a2cf287080cf8
Last active September 29, 2021 11:28
Mapping some toy music subgenres
# https://raw.githubusercontent.com/gkaramanis/tidytuesday/master/2021/2021-week37/billboard.R
# https://twitter.com/ttso/status/1442485258172043268
billb_feat <- billb_feat %>%
mutate(
subgenre = case_when(
str_detect(spotify_genre, "rock") ~ "1",
str_detect(spotify_genre, "folk") ~ "2",
str_detect(spotify_genre, "pop") ~ "3",
str_detect(spotify_genre, "jazz") ~ "4",
@tts
tts / makeboolean.R
Last active February 28, 2021 13:26
Handling a Boolean query
library(stringr)
library(tidyverse)
#---------------------------------------------------------------
# https://twitter.com/nealhaddaway/status/1362512900716433409
#
# His example query
#--------------------------------------------------------------
q <- "((arable OR agricult* OR farm* OR crop* OR cultivat* OR field*) AND
(plough* OR plow* OR till* OR 'direct drill*' OR fertili* OR biosolid* OR
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tts
tts / 2019altmTop100aff.R
Created December 19, 2019 07:32
2019 Altmetric Top 100 geocoded affiliations on world map
library(tidyverse)
library(readxl)
library(tmaptools)
library(maps)
library(sf)
url <- "https://altmetric.figshare.com/ndownloader/files/20202618"
temp <- tempfile()
download.file(url, temp)
data <- read_excel(temp)
library(tidyverse)
library(sf)
# Data from hri.fi
districts <- st_read("PKS_Kartta_Rajat_KML2011/PKS_suuralue.kml")
hki <- districts %>%
filter(Name %in% c("Eteläinen", "Itäinen","Läntinen","Kaakkoinen",
"Keskinen","Pohjoinen","Koillinen")) %>%
mutate(Name_en = case_when(
@tts
tts / energy.R
Last active January 20, 2019 13:34
Line graph on energy production in district heating of the Helsinki capital area
library(tidyverse)
library(readxl)
library(httr)
#-------------------------------------------------------------
# hri.fi
#
# Pääkaupunkiseudun kaukolämmön tuotannon energialähteet (GWh)
#-------------------------------------------------------------
@tts
tts / addMissingYears.vb
Last active July 11, 2017 14:30
Transform Pure activities data by filling in rows with missing year
Public Sub addMissingYears()
Dim readFrom As Long 'Row we read from
Dim writeTo As Long 'Row we write to
Dim allRows As Long 'Row count to loop over
Dim thisC As Long
Dim thisD As Long
Dim sheetFrom As Worksheet 'Sheet where we read from
Dim sheetTo As Worksheet 'Sheet where we write to
@tts
tts / pure2powerbi.R
Last active July 10, 2017 10:18
Transform Pure activities data exported as Excel to be imported into Power BI for reporting
# `dataset` holds the input data for this script
library(dplyr)
names(dataset) <- c("Type", "Unit", "Start", "End")
dataset$Unit <- iconv(dataset$Unit, from = "WINDOWS-1252", to = "UTF-8")
# We need to expand those rows where Start and End span more than one year,
# e.g. 2010-2012 into 2010, 2011, 2012
to_expand <- dataset %>%
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(grid)
data20162017 <- read.csv("toshiny_altm_2016_2017.csv", stringsAsFactors = FALSE)
data20162017 <- data20162017 %>%
mutate(gap_cites = Citations2017 - Citations,