-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathridge_plotteR.r
45 lines (40 loc) · 2.02 KB
/
ridge_plotteR.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Author: Jeffrey Grover
# Purpose: Create ridge plots using the ggridges package
# Created: 2019-04-19
# Usage: Ridge plots are a nice visualization for data that allows you to not
# see the same data a violin or box plot would show, but also the shape of the
# data. It doesn't suffer from the artificially inflated median-look of the
# violin plot, and turning it horizontal by default focuses the eye on the fact
# that the density is highest near the median, rather than on the extremes.
library(dplyr)
library(ggplot2)
library(ggridges)
# ggridges is not a part of the tidyverse libraries, it is a separate package
# that must be installed and loaded. While, dplyr and ggplot2 will work by import
# of library(tidyverse).
# In this example, "data" is a data frame or tibble in long format with variables
# (columns) "sample" and "expression"
colorblind_palette <- rev(c('#999999', '#E69F00', '#56B4E9', '#009E73', '#F0E442',
'#0072B2', '#D55E00', '#CC79A7'))
ggplot(data, aes(y = sample, x = expression, fill = sample)) +
geom_density_ridges2(scale = 0.95,
jittered_points = TRUE,
position = position_points_jitter(width = 0.05, height = 0),
point_shape = '|',
point_size = 5,
point_alpha = 0.5,
alpha = 1) +
stat_density_ridges(quantile_lines = TRUE,
quantiles = c(0.10, 0.50, 0.90),
scale = 0.95) +
theme_bw(base_size = 24) +
scale_x_continuous(limits = c(0, 14)) +
scale_y_discrete(expand = expand_scale(add = c(0.2, 0.8))) +
scale_fill_manual(values = colorblind_palette) +
theme(axis.title.y = element_blank(),
axis.text.y = element_text(color = 'black'),
axis.text.x = element_text(color = 'black'),
legend.title = element_blank(),
legend.position = 'none') +
xlab('Expression')
ggsave(str_c(out_dir, 'out_filename.svg'), width = 10, height = 8)