Snippets

Dénes Türei plot correlation with hexagonal bins

Created by Dénes Türei last modified
#!/usr/bin/env python3

# Dénes Türei EMBL 2017
# turei.denes@gmail.com

import lima

l = lima.Lima()

# data from csv inserted into an xlsx sheet:
l.infile_new = '170829_charlotte_dataset.xlsx'

l.read_new_table()

# this creates nbi_corr.tab
l.export_affy_corr()

# this creates log10fc2_corr.tab
l.export_affy_corr(metric = 'log10fc2')
#!/usr/bin/env Rscript

# Denes Turei EMBL 2017
# turei.denes@gmail.com

library(ggplot2)

# do not forget to install package `hexbin` before running this

# NBI correlation plot
nbic <- read.table('nbi_corr.tab', sep = '\t', header = FALSE)
names(nbic) <- c('a', 'b')
nbi.cor <- cor.test(log10(nbic$a), log10(nbic$b))

p <- ggplot(nbic, aes(x = a, y = b)) +
    geom_hex(bins = 130) +
    geom_smooth(method = 'lm', color = 'red', size = .2) +
    scale_x_log10() +
    scale_y_log10() +
    #scale_fill_continuous(guide = guide_legend(title = 'Count'), breaks = seq(0, 200, 40)) +
    scale_fill_gradient(
        low = '#CCCCCC',
        high = '#000000',
        space = 'Lab',
        guide = guide_legend(title = 'Count'), breaks = seq(0, 200, 40)) +
    xlab('log10(NBI)') +
    ylab('log10(NBI)') +
    ggtitle('Correspondance of independent NBI values') +
    theme_bw() +
    theme(
        text = element_text(family = "DINPro"),
        #axis.title = element_text(size = 24),
        #axis.text.x = element_text(angle = 90, vjust = 0.5, size = 9, hjust = 1)
    )

ggsave('nbi_corr.pdf', device = cairo_pdf, width = 6, height = 5.2)

log10fcc <- read.table('log10fc2_corr.tab', sep = '\t', header = FALSE)
names(log10fcc) <- c('a', 'b')
log10fc.cor <- cor.test(log10fcc$a, log10fcc$b)

log10fcc <- log10fcc[log10fcc$a != 0 & log10fcc$b != 0,]

p <- ggplot(log10fcc, aes(x = a, y = b)) +
    # geom_point(size = .1, alpha = .2) +
    geom_hex(bins = 130) +
    geom_smooth(method = 'lm', color = 'red', size = .2) +
    scale_fill_continuous(guide = guide_legend(title = 'Count'), breaks = seq(0, 200, 40)) +
    scale_fill_gradient(
        low = '#CCCCCC',
        high = '#000000',
        space = 'Lab',
        guide = guide_legend(title = 'Count'), breaks = seq(0, 200, 40)) +
    xlab('log10(FC)') +
    ylab('log10(FC)') +
    ggtitle('Correspondance of independent fold change values') +
    theme_bw() +
    theme(
        text = element_text(family = "DINPro"),
        #axis.title = element_text(size = 24),
        #axis.text.x = element_text(angle = 90, vjust = 0.5, size = 9, hjust = 1)
        )

ggsave('log10fc_corr.pdf', device = cairo_pdf, width = 6, height = 5.2)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.