Skip to content

Instantly share code, notes, and snippets.

View tts's full-sized avatar

Tuija Sonkkila tts

View GitHub Profile
@tts
tts / global.R
Last active February 18, 2022 05:28
Finnish Breeding Bird Atlas (1-2) open data as a Shiny web app
library(shiny)
library(leaflet)
library(shinythemes)
library(dplyr)
# See http://tuijasonkkila.fi/blog/2015/03/birds-on-a-map/
# http://atlas3.lintuatlas.fi/taustaa/kaytto
#
# linnut <- read.table("lajit.csv", sep = ",", stringsAsFactors = F, quote = "")
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
@tts
tts / gist:4977062
Last active December 9, 2020 11:14
Transform a WordPress export XML file to HTML
<!--
First export blog posts from WordPress, and then transform the exported XML file to HTML
with e.g. Saxon
java -jar saxon9.jar wordpress.2013-02-17.xml wp2html.xsl >wp.html
Tuija Sonkkila, 17.2.2013
-->
Loading
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 / global.R
Last active January 16, 2018 02:02
Shiny application on visualizing text-mining outputs of REF2014 impact case studies
library(shiny)
library(shinydashboard)
library(dplyr)
library(tidyr)
library(ggvis)
library(DT)
library(d3heatmap)
load("ref2014impact.Rda")