Skip to content

Instantly share code, notes, and snippets.

View jlehtoma's full-sized avatar

Joona Lehtomäki jlehtoma

  • Helsinki
View GitHub Profile
@jlehtoma
jlehtoma / plot_funding.R
Last active March 13, 2019 20:03
Opetus- ja kulttuuriministeriön HY:lle myöntämän perusrahoituksen kehitys 2010–2020
library(hrbrthemes)
library(tidyverse)
dat <- tibble::tibble(year = factor(c(2010:2017, paste0("A", 2018:2020))),
funding = c(400, 410, 431, 423, 431, 446, 404, 395,
390, 383, 374))
p1 <- dat %>%
ggplot(aes(x = year, y = funding)) +
geom_bar(stat = "identity", width = 0.4) +
@jlehtoma
jlehtoma / hexfin.R
Created February 2, 2019 13:17
Create hexagon grid for Finland
library(magick)
library(raster)
library(rgeos)
library(sf)
library(sp)
library(tidyverse)
set.seed(1)
# Helper functions --------------------------------------------------------
@jlehtoma
jlehtoma / hki_aluejako.R
Created June 6, 2018 18:08
Get aluejakokartat data for Helsinki
library(sf)
# Define source from where the data is downloaded
source_url <- "https://kartta.hel.fi/avoindata/aineistot/HKI-aluejako-1995-2016-gpkg.zip"
target_dir <- "data"
# Make target dir if it doesn't exist
if (!dir.exists(target_dir)) {
dir.create(target_dir)
}
@jlehtoma
jlehtoma / ohjeet.md
Last active April 18, 2018 17:59
Ohjeet Zonation-rasterin visualisointiin QGIS-ohjelmalla

Nämä ohjeet on tehty QGIS:in 2.18 -versiolla. Uusin versio on 3.0, jossa komentojen nimet / paikat ovat saattaneet hieman muuttua. QGIS-ohjelman voit ladata täältä.

Analyysien taustat, aineistot ja toteutus on kuvattu raportissa Monimuotoisuudelle tärkeät metsäalueet Suomessa. Tutustu raporttiin ennen tulosaineistoihin perehtymistä!

  1. Lataa Monimuotoisuudelle tärkeät metsäalueet 2018 (Zonation) -aineisto koneellesi ja pura zip-tiedosto.
  2. Layer > Add Raster Layer > valitse joku Zonation-tulosrastereista
  3. Lataa värimäärittelytiedosto täältä koneellesi ( selaimessa Save As tms)
  4. Tuplaklikkaa Layer Panel:issa 2-kohdassa lisäämääsi Zonation-tulosraster
@jlehtoma
jlehtoma / zonation_RdYlBu.qml
Created April 18, 2018 17:06
RdYlBu color scheme for Zonation output rasters
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="2.1.0-Master" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
<pipe>
<rasterrenderer opacity="1" alphaBand="0" classificationMax="1" classificationMinMaxOrigin="User" band="1" classificationMin="0" type="singlebandpseudocolor">
<rasterTransparency/>
<rastershader>
<colorrampshader colorRampType="DISCRETE" clip="0">
<item alpha="255" value="0.2" label="0.00 - 0.20" color="#4575B4"/>
<item alpha="255" value="0.5" label="0.20 - 0.50" color="#91BFDB"/>
<item alpha="255" value="0.75" label="0.50 - 0.75" color="#E0F3F8"/>
library(tidyverse)
# Helper functions --------------------------------------------------------
process_sp <- function(sp) {
message("Processing species: ", sp, "...")
# Seuraava käskyjoukko tuottaa kolmiosaisen kuvaajan, jossa ylin kuvaaja kertoo paikallismäärien
# vaihtelun vuoden aikana ja keskimmäinen muuttajien vastaavan vaihtelun. Kuvaajissa x-akselilla on
Top 3.94%
Amphibians Birds Freshwater fish Mammals Plants Reptiles
Amphibians 1.00000000 0.10976019 0.07313933 0.1665817 0.14020769 0.1532886
Birds 0.10976019 1.00000000 0.08673298 0.1280185 0.13937816 0.1598971
Freshwater fish 0.07313933 0.08673298 1.00000000 0.0691273 0.08017331 0.0798534
Mammals 0.16658172 0.12801850 0.06912730 1.0000000 0.18084051 0.1759870
Plants 0.14020769 0.13937816 0.08017331 0.1808405 1.00000000 0.1862069
Reptiles 0.15328863 0.15989709 0.07985340 0.1759870 0.18620690 1.0000000
library(rvest)
library(stringr)
library(tidyverse)
base_url <- "http://www.metsakartat.fi/"
get_zip <- function(x) {
message("Downloading ", x, "...")
download.file(x, basename(x), "internal")
return(invisible(TRUE))
@jlehtoma
jlehtoma / correlation_pairs.R
Created March 27, 2017 15:51
Plot correaltion pairs
# panel.smooth function is built in.
# panel_cor puts correlation in upper panels, size proportional to correlation
panel_cor <- function(x, y, digits=2, prefix="", cex.cor, ...) {
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits = digits)[1]
txt <- paste(prefix, txt, sep = "")
if (missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor * r)
This file has been truncated, but you can view the full file.
-- Start of simulation at: 13:18:36 --
demand file used: demand.in1
region file used: region1.fil.asc
number of cover types: 22
number of regions: 1
number of factors in 1 equation: 17
total number of factors: 23
number of demand types: 5