Skip to content

Instantly share code, notes, and snippets.

View johncolby's full-sized avatar

John Colby johncolby

  • Marin Health
  • San Francisco, CA
View GitHub Profile
@johncolby
johncolby / macos_retina_compared.md
Last active July 6, 2023 19:50
macOS retina scaling comparison

macOS hiDPI retina scaling options compared

These are some photos comparing different macOS retina scaling options. All use a non-vector test pattern displayed at 100% (AAPM TG18). All photos are taken at roughly the same distance, using the same crop. Forgive the slight hand-held motion blur, and focus on these variables:

  • Pixel size
  • UI size
  • Pixel perfection (has any interpolation taken place?)
  • Real estate (how much of the image is displayed in this representative patch?)

Dell U2713H

@johncolby
johncolby / textplot.R
Created December 15, 2011 21:27
Modification to textplot() from gplots to allow for better justification
# $Id: textplot.R 1213 2007-11-01 20:20:10Z warnes $
textplot <- function(object, halign="center", valign="center", cex, ... )
UseMethod('textplot')
textplot.default <- function(object,
halign=c("center","left","right"),
valign=c("center","top","bottom"),
cex, ... )
Pf1 Pf2 Pf3 Pf4
0.4 0.3 0.1 0.6
0.1 0.7 0.7 1
0.4 0.9 0.5 0.7
0.3 0.4 0.4 0.7
1 0.8 0.4 0.2
0.4 0 0.3
0.4 0.8 0.5
0.1 0.2
0.2 0.2
@johncolby
johncolby / rowname_index.R
Created November 1, 2011 20:18
Example showing indexing/replacement by row names
original = expand.grid(ID1=c('a', 'b', 'c'), ID2 = c('red', 'green', 'blue'))
original$value = 0
replacement = data.frame(ID1='b', ID2='red', value=1)
rownames(original) = paste(original$ID1, original$ID2)
rownames(replacement) = paste(replacement$ID1, replacement$ID2)
original[rownames(replacement), ] = replacement
@johncolby
johncolby / fft_convolution.R
Created October 27, 2011 17:15
An example showing the benefits of FFT convolution vs. manual calculation
require(plyr)
set.seed(12345)
n = 10
n.sum = 2
# Simulate data
a = sample.int(10, n, replace=T)
df = data.frame(n=1:n, a)
@johncolby
johncolby / bias_correct.R
Created October 26, 2011 18:22
An example of how each column in a data frame could be residualized for some covariates
# Download example data from: https://github.com/johncolby/SVM-RFE/zipball/master
setwd('/path/to/SVM-RFE/') # Change this to your setup
load('demo/input.Rdata')
data = input[, 2:3]
input = input[, -(1:3)]
# Function to residualize a vector x for the covariates in data
residualize <- function(x, fun=x~., data) {
-1.22920245520088 1.26297072626596 1.83337525320795
1.20936180458861 0.611215979963239 -1.30133702133403
0.522987838117479 -0.451731971345027 -0.58388185591968
0.101340272969554 -0.435726497850704 0.569398963635685
0.426031516466784 0.151080475310323 0.956491447694583
-0.252059713648723 -0.175471660877733 -0.980883888395024
0.662052189667485 1.33212600996006 -1.47268894052709
1.48817331808508 -0.0473711069814109 -0.492789669961388
-0.503441036994115 -0.294926138113795 0.366179342735957
-2.12920560829524 1.02332212331524 -1.58266122316052
@johncolby
johncolby / sub_means_example.R
Created June 22, 2011 17:23
An example showing how to obtain the mean for each subject across multiple observations in a data frame
library(plyr)
data = arrange(data.frame(ID=1:10, FA=runif(50, 0.2, 0.8)), ID)
ddply(data, 'ID', mean) # using plyr library
aggregate(data, list(ID=data$ID), mean) # using base
@johncolby
johncolby / Longitudinal data example.R
Created June 1, 2011 20:16
An example showing how to plot longitudinal data in R using base graphics and ggplot2
library(plyr)
library(ggplot2)
# Simulate data
numSubs = 40
x = runif(numSubs, 0, 30)
x = c(x, x + abs(rnorm(numSubs, 2)))
y = 2 + x - 0.02*x^2 + rnorm(2*numSubs, 0, 1)
@johncolby
johncolby / colorbar.R
Created May 26, 2011 19:16
An R function to generate color bar legends for neuroimaging plots
# Function to plot color bar
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') {
scale = (length(lut)-1)/(max-min)
dev.new(width=1.75, height=5)
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title)
axis(2, ticks, las=1)
for (i in 1:(length(lut)-1)) {
y = (i-1)/scale + min
rect(0,y,10,y+1/scale, col=lut[i], border=NA)