Skip to content

Instantly share code, notes, and snippets.

View loukesio's full-sized avatar
🧑‍💻
Coding at work

Loukas Theodosiou loukesio

🧑‍💻
Coding at work
View GitHub Profile
@z3tt
z3tt / striptext-inside.R
Last active January 9, 2026 00:13
Place Striptext inside Facet Panels with ggplot2
library(ggplot2)
gm_2023 <- readr::read_csv("https://www.cedricscherer.com/data/gapminder-2023.csv")
pal <- c(Africa = "#00D9EE", Americas = "#4CF101", Asia = "#FF4670", Europe = "#FFE702", Oceania = "#CA4ADC")
# base plot
g <-
ggplot(gm_2023, aes(x = gdp_pcap, y = life_exp, size = pop)) +
geom_point(
color = "white",
data(diamonds, package = "ggplot2")
# Most straightforward
diamonds$ppc <- diamonds$price / diamonds$carat
# Avoid repeating diamonds
diamonds$ppc <- with(diamonds, price / carat)
# The inspiration for dplyr's mutate
diamonds <- transform(diamonds, ppc = price / carat)
@juliasilge
juliasilge / eurovision.md
Last active June 17, 2022 10:10
Eurovision voting from #TidyTuesday
library(tidyverse)
library(widyr)
library(maps)
#> 
#> Attaching package: 'maps'
#> The following object is masked from 'package:purrr':
#> 
#>     map
eurovision_votes <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-17/eurovision-votes.csv')
library(gt)
library(gtExtras)
library(dplyr)
library(htmltools)
# original source: https://www.bloomberg.com/graphics/2021-german-election-results/
party_df <- tibble(
Party = c("SPD", "CDU/CSU", "Greens", "FDP", "AfD", "Left", "Other"),
Seats = c(206, 196, 118, 92, 83, 39, 1),
# What's the most natural way to express this code in base R?
library(dplyr, warn.conflicts = FALSE)
mtcars %>%
group_by(cyl) %>%
summarise(mean = mean(disp), n = n())
#> # A tibble: 3 x 3
#> cyl mean n
#> <dbl> <dbl> <int>
#> 1 4 105. 11
#> 2 6 183. 7
@ghuertaramos
ghuertaramos / PlantPhylomoji.R
Last active October 23, 2023 00:22
Script to make a plant phylogeny using emojis
library(ggplot2)
library(ggtree)
library(emojifont)
tree_text <- "(evergreen_tree,(avocado,((tulip, ( palm_tree, ( banana, ( pineapple, (corn, ( tanabata_tree, ear_of_rice )))))),((grapes, (((peanuts, shamrock), ((( rose, strawberry ), ((apple, pear ), ( peach, (cherry_blossom, cherries) ))), (chestnut, (jack_o_lantern, (watermelon, (cucumber, melon)))))), (hibiscus, (( tangerine, lemon ), (maple_leaf))))),(cactus, (kiwi_fruit, ((sweet_potato, (hot_pepper, (eggplant, (potato, tomato)))), (carrot,(sunflower, blossom)))))))));"
x <- read.tree(text=tree_text)
ggtree(x, layout="circular") +
xlim(NA, 13) + ylim(NA, 39) +
geom_tiplab(aes(color=label), parse='emoji', size=6, vjust=0.5, hjust = 0.5, offset = 0.6) +
@tylermorganwall
tylermorganwall / cholera_snow.R
Last active November 5, 2020 23:34
John Snow's cholera clusters, visualized in 3D with rayshader and ggplot2
#theme and ggplot derived from David Kretch, his code: https://github.com/davidkretch/london_cholera_map/blob/master/london_cholera_map.R
library(HistData)
library(ggplot2)
library(ggpointdensity)
library(rayshader)
deaths = Snow.deaths
streets = Snow.streets
@brfitzpatrick
brfitzpatrick / SLURM_foreach.md
Last active February 7, 2024 18:03
minimal example of using `foreach` parallelism on a clusters managed by SLURM

Job script:

#!/bin/bash

#SBATCH --job-name=rfee
#SBATCH --workdir=/home/user.name/rfee/
#SBATCH --output=r_foreach_example_console_output.txt
#SBATCH --mem-per-cpu=100 # specify RAM per CPU here in Mb
#SBATCH --time=0:02:00
@lnalborczyk
lnalborczyk / regression_optimisation.R
Last active January 2, 2023 13:05
Illustrating the Nelder & Mead (1965)'s optimisation method using gganimate
############################################################################
# estimation via the base R optim function
# code adapted from Farrell & Lewandowsky (2018, ch.3)
# https://github.com/psy-farrell/computational-modelling
#################################################################
library(hrbrthemes)
library(tidyverse)
library(gganimate)
library(magick)
@darencard
darencard / ucsc_genome_track_setup.md
Last active November 4, 2023 09:16
Creating a UCSC Genome Track for viewing genome annotations
layout title date excerpt
posts
Visualizing Genome Annotations
2019-01-25
Creating a UCSC Genome Track for Viewing Genome Annotations

Creating a UCSC Genome Track for Viewing Genome Annotations

When creating a custom, in-house genome annotation, there is no straight-forward way to share it upon publication. NCBI does not accept and archive these, so most users just end up depositing the text files in an online repository. The UCSC Genome Browser team has fortunately come up with a decent way to share an annotation in a graphical manner, so readers can browse the assembly and annotation at some level without a lot of work.