Skip to content

Instantly share code, notes, and snippets.

View flashton2003's full-sized avatar

flashton2003

View GitHub Profile
@flashton2003
flashton2003 / histo_from_postgres_in_r
Last active August 29, 2015 14:18
histo_from_postgres_in_r
library(ggplot2)
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con = dbConnect(drv, dbname = 'dbname', host = 'postgres', user = 'user', password = 'password')
query <- 'select * from your_table'
res <- dbSendQuery(con, query)
data_from_db <- fetch(res, n = -1) # n = -1 means all results will be returned
@flashton2003
flashton2003 / ete2.eg.py
Created November 4, 2014 17:30
Annotate a tree with a heat map
def plot_heat_tree(heatmap_file, tree_file, output_file=None):
'''
Plot heatmap next to a tree. The order of the heatmap **MUST** be the same,
as order of the leafs on the tree. The tree must be in the Newick format. If
*output_file* is specified, then heat-tree will be rendered as a PNG,
otherwise interactive browser will pop-up with your heat-tree.
Parameters
----------
heatmap_file: str
@flashton2003
flashton2003 / gist:4d9c2ccc34f8e1d9e321
Last active August 29, 2015 14:02
ggplot histogram
install.packages('ggplot2')
library(ggplot2)
## simple histogram
data <- read.delim("path/to/data")
ggplot(data, aes(x = data$V1)) + geom_histogram(binwidth = 30000)
## more complex - with axis labels and custom scaling - more info http://www.cookbook-r.com/Graphs/Plotting_distributions_(ggplot2)/
@flashton2003
flashton2003 / gist:6e0edaf7105c5093937d
Created May 25, 2014 09:48
Hertfordshire number of measles cases
1996 2
1999 1
2001 1
2002 4
2003 13
2004 3
2005 2
2006 9
2007 59
2008 37
@flashton2003
flashton2003 / gist:b3e319d0c641b31e3699
Last active August 29, 2015 14:01
east london and city number of cases of measles
1995 1
1996 3
1999 4
1998 1
2002 13
2003 10
2000 31
2001 2
2006 21
{
"metadata": {
"name": "",
"signature": "sha256:dd3f380620371d7def93011e81b190a7a8f796fba0551a284b06626a6757a641"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"metadata": {
"name": "",
"signature": "sha256:dd3f380620371d7def93011e81b190a7a8f796fba0551a284b06626a6757a641"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"metadata": {
"name": "",
"signature": "sha256:b5d9c057e15441865c84a9422297988c0e93d5961f3da2e00ebd3be695766282"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [