Skip to content

Instantly share code, notes, and snippets.

pred <- ddply(data.frame(x=c(5:65)*0.01), .(x), function(t) data.frame(x = t$x, y = c(5:85)*0.01) )
pred$enrichment <- predict(sigmoid, pred)
max_pred <- max(pred$enrichment, d$enrichment)
p <- ggplot(pred,aes(x,y))+geom_tile(aes(fill=enrichment))+scale_fill_gradient(low = "white", high = "steelblue",limits=c(0,max_pred))
p <- p + xlab("x") + ylab("y")
p <- p + geom_point(data=d,aes(x=x, y=y, colour=enrichment),size=20) +scale_colour_gradient(low = "white", high = "steelblue",limits=c(0,max_pred))
print(p)
@mkuhn
mkuhn / gist:862551
Created March 9, 2011 17:04
Comparing two-dimensional distributions using ggplot2
p <- ggplot(d,aes(x+0.05,y+0.05))+geom_tile(aes(fill=enrichment)) + scale_fill_gradient(low="white", high="steelblue", limits=c(0,120))
p <- p + xlab("x") + ylab("y")
p <- p + geom_point(aes(x=x+0.05, y=y+0.05, colour=pred),size=20) + scale_colour_gradient(low="white", high="steelblue", limits=c(0,120))
print(p)
@mkuhn
mkuhn / igrep.py
Created January 5, 2011 08:21
a small utility for repeatedly (and interactively) running grep on the same file
#!/usr/bin/env python
import readline
import os
import sys
import re
if len(sys.argv) == 1:
print >> sys.stderr, "Usage: igrep[.py] file1 [file2 ...]"
#!/usr/bin/perl -w
my $columns = 50;
my $gapped = 0;
my $progname = $0;
$progname =~ s/^.*?([^\/]+)$/$1/;
my $usage = "Usage: $progname [<Stockholm file(s)>]\n";
$usage .= " [-h] print this help message\n";
# with the help of decorators, keep track of the functions
# we would like to use for fitting
fit_functions = []
def fit_func(f):
fit_functions.append(f)
return f
class C(object):
library(dplyr)
a <- data.frame(foo = 1:10, bar = "bar")
b <- tbl_df(a)
a[,1]
b[,1]
paste0(a[,1], "!")
paste0(b[,1], "!")
@mkuhn
mkuhn / gist:9ad4da2e039e5c6741e2
Created March 10, 2015 16:00
Composite figures using ggplot2 and gtable
library(ggplot2)
library(gtable)
# create example data
set.seed(42)
dataset_names <- c("Human", "Mouse", "Fly", "Worm")
datasets <- data.frame(name = factor(dataset_names, levels=dataset_names), parity = factor(c(0, 0, 1, 0)), v50 = runif(4, max=0.5), y=1:4)
data <- data.frame( dataset1 = rep(datasets$name, 4), dataset2 = rep(datasets$name, each = 4), z = runif(16,min = 0, max = 0.5) )
pal <- c("#dddddd", "#aaaaaa")