Skip to content

Instantly share code, notes, and snippets.

Avatar

Tuija Sonkkila tts

View GitHub Profile
View q_dbpedia_sparql_httr.R
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 Sep 29, 2021
Mapping some toy music subgenres
View gist:9c953059d4686c634d5a2cf287080cf8
# 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 Feb 28, 2021
Handling a Boolean query
View makeboolean.R
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
View rtnetworkwithtweets.ipynb
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 Dec 19, 2019
2019 Altmetric Top 100 geocoded affiliations on world map
View 2019altmTop100aff.R
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)
View hkitrees_viz.R
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 Jan 20, 2019
Line graph on energy production in district heating of the Helsinki capital area
View energy.R
library(tidyverse)
library(readxl)
library(httr)
#-------------------------------------------------------------
# hri.fi
#
# Pääkaupunkiseudun kaukolämmön tuotannon energialähteet (GWh)
#-------------------------------------------------------------
@tts
tts / addMissingYears.vb
Last active Jul 11, 2017
Transform Pure activities data by filling in rows with missing year
View addMissingYears.vb
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 Jul 10, 2017
Transform Pure activities data exported as Excel to be imported into Power BI for reporting
View pure2powerbi.R
# `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 %>%
View changes_metrics_small_multiples.R
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,