Skip to content

Instantly share code, notes, and snippets.

View JoachimGoedhart's full-sized avatar
💡
Coding now and then

Joachim Goedhart JoachimGoedhart

💡
Coding now and then
View GitHub Profile
@JoachimGoedhart
JoachimGoedhart / Beeswarm
Created April 3, 2026 08:35
Copy-paste into the address bar of a browser
data:text/html,<canvas id=x><script>x.width=x.height=400;X=x.getContext`2d`;A=0;P=[...Array(200)].map((_,i)=>({x:200,y:200,vx:0,vy:0,h:i*1.8}));function f(){A+=0.02;tx=200+Math.cos(A)*120+Math.cos(A*2.3)*60+Math.cos(A*0.7)*40;ty=200+Math.sin(A*1.3)*100+Math.sin(A*2.7)*50+Math.sin(A*0.5)*40;X.fillStyle='rgba(0,0,0,0.08)';X.fillRect(0,0,400,400);P.forEach(p=>{dx=tx-p.x;dy=ty-p.y;d=Math.sqrt(dx*dx+dy*dy)||1;p.vx+=dx*0.015+(Math.random()-.5)*1.5;p.vy+=dy*0.015+(Math.random()-.5)*1.5;p.vx*=0.93;p.vy*=0.93;p.x+=p.vx;p.y+=p.vy;X.beginPath();X.arc(p.x,p.y,1,0,6.28);X.fillStyle='hsl('+p.h+',100%,65%)';X.fill()});X.beginPath();X.arc(tx,ty,2,0,6.28);X.fillStyle='rgb(255,255,255)';X.fill();requestAnimationFrame(f)}f()</script>
@JoachimGoedhart
JoachimGoedhart / ggplot2_geom_point-shapes
Last active September 26, 2022 20:09
Plotting all available shapes&labels for geom_point()
library(tidyverse)
x <- rep(0:15, 8)
y <- rep(0:7, each=16)
shape <- 0:127
df_shapes <- data.frame(x=x, y=y, shape=shape) %>%
filter(!shape %in% c(26:31)) #Shapes 26-31 are not defined, so we'll remove those
ggplot(data=df_shapes, aes(x,y)) +
// Macro to add a column with the time in the 'Results' window
// The time is calculated from the Frame interval defined by the user
// In this macro the time interval is defined by the variable 'interval'
// Created by Joachim Goedhart with essential input from Jerome Mutterer (@jmutterer)
//Set the interval (alternatively it can be set in ImageJ/FIJI from the menu: [Image > Properties...])
interval=2
Stack.setFrameInterval(interval)
//Calculate the time for each frame and add to the results window
@JoachimGoedhart
JoachimGoedhart / Randomization_test.R
Last active October 14, 2018 18:59
R-script that calculates a p-value using a randomization test to generate the H0 distribution
#Function that returns p-values from randomization/permutation test
require(dplyr)
require(tidyr)
#Set number of randomizations
nsteps <- 1000
#Read the dataframe - the example data used below is available at: https://github.com/JoachimGoedhart/PlotsOfData
df <- read.csv("Data_wide_example.csv")
@JoachimGoedhart
JoachimGoedhart / Read-all-csv-files-into-dataframe.R
Last active November 22, 2025 19:37
Reads all *.csv files from working directory and moves the data into a single dataframe
require(data.table)
require(dplyr)
#Get a list with all csv files from the directory that is set as 'working directory'
filelist = list.files(pattern="*.csv$")
#read all csv files with data.table::fread() and put in df_input_list
df_input_list <- lapply(filelist, fread)
#reading in csv files can also be done using the base R function read.csv(), without needing to load package "data.table":
@JoachimGoedhart
JoachimGoedhart / Tol-qualitative-palettes.R
Last active July 27, 2020 13:43
Generates vectors (for R) that hold a color palette that is colorblind safe
#Several qualitative color palettes that are colorblind friendly
#From Paul Tol: https://personal.sron.nl/~pault/
#Code to generate vectors in R to use these palettes
Tol_bright <- c('#EE6677', '#228833', '#4477AA', '#CCBB44', '#66CCEE', '#AA3377', '#BBBBBB')
Tol_vibrant <- c('#EE7733', '#0077BB', '#33BBEE', '#EE3377', '#CC3311', '#009988', '#BBBBBB')
Tol_muted <- c('#332288', '#88CCEE', '#44AA99', '#117733', '#999933', '#DDCC77', '#CC6677', '#882255', '#AA4499', '#DDDDDD')
@JoachimGoedhart
JoachimGoedhart / Dataframe_with_summary-of-data.R
Created June 8, 2018 20:24
Reads non-tidy time-dependent data and calculates statistics
#Reads a non-tidy (wide) dataframe from csv file and assumes first column to be time, remaining columns measured parameter (Ratio) per condition (Cell).
df_wide <- read.csv("FRET-ratio-wide.csv", na.strings = "")
#Tidy the data, i.e. long format with each row is variable
df_tidy <- gather(df_wide, Cell, Ratio, -Time)
######### Calulcate summary statistics to fill dataframe 'df_summary' ########
# This is base R approach
df_summary <- data.frame(Time=df_wide$Time, n=tapply(df_tidy$Ratio, df_tidy$Time, length), mean=tapply(df_tidy$Ratio, df_tidy$Time, mean))
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {