Snippets

Dénes Türei Triangle double heatmap with ggplot::geom_point

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

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

require(ggplot2)
require(dplyr)

data <- data.frame(
    val = rnorm(40),
    grp = c(rep('a', 20), rep('b', 20)),
    x   = rep(letters[1:4], 5),
    y   = rep(letters[1:5], 4)
) %>%
mutate(
    sym = ifelse(grp == 'a', "\u25E4", "\u25E2")
)

p <- ggplot(data, aes(x = x, y = y, fill = val)) +
    geom_tile() +
    theme_linedraw()

ggsave('test-tile1.pdf', device = cairo_pdf, width = 4, height = 5)


p <- ggplot(data, aes(x = x, y = y, color = val, shape = grp)) +
    geom_point(size = 18) +
    scale_shape_manual(values=c("\u25E4","\u25E2")) +
    theme_minimal()

ggsave('test-tile2.pdf', device = cairo_pdf, width = 4.1, height = 3.5)


# same with geom_text so the typeface can be set explicitely:
p <- ggplot(data, aes(x = x, y = y, color = val, label = sym0)) +
    geom_text(size = 18, family = 'DejaVu Sans') +
    theme_minimal() +
    theme(
        #text = element_text(family = 'DINPro'),
        panel.grid = element_blank()
    )

ggsave('test-tile3.pdf', device = cairo_pdf, width = 4.1, height = 3.5)

Comments (0)

HTTPS SSH

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