-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizing_scatterbar.Rmd
93 lines (70 loc) · 2.25 KB
/
customizing_scatterbar.Rmd
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "Customizing scatterbar"
author: "Jean Fan"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Customizing scatterbar}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Simulate some data for demo purposes
```{r simulate}
library(scatterbar)
pos <- data.frame(x = c(1,1,2,2),
y = c(1,2,1,2))
prop <- matrix(c(0.5, 0.5, 0, 0,
0.5, 0, 0, 0.5,
0, 0.5, 0.5, 0,
0, 0, 0.5, 0.5), nrow=4)
rownames(pos) <- rownames(prop) <- c('a','b','c','d')
colnames(prop) <- c('p1', 'p2', 'p3', 'p4')
print(pos)
print(prop)
```
Examples of customization using `ggplot2`
```{r pressure}
create_scatterbar(prop, pos)
create_scatterbar(prop, pos) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1,
padding_x = 0.1, padding_y = 0.1) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1,
padding_x = 0.1, padding_y = 0.1) +
ggplot2::theme_bw() + ggplot2::ylab('y') +
ggplot2::coord_flip()
```
What if my proportions don't add up to 1?
```{r test}
prop <- matrix(c(0.1, 0.2, 0, 0,
0.1, 0, 0, 0.4,
0, 0.2, 0.3, 0,
0, 0, 0.3, 0.4), nrow=4)
rownames(prop) <- c('a','b','c','d')
colnames(prop) <- c('p1', 'p2', 'p3', 'p4')
print(prop)
create_scatterbar(prop, pos)
create_scatterbar(prop, pos) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1,
padding_x = 0.1, padding_y = 0.1) +
ggplot2::theme_bw() + ggplot2::ylab('y')
create_scatterbar(prop, pos,
x_scale = 1, y_scale = 1,
padding_x = 0.1, padding_y = 0.1) +
ggplot2::theme_bw() + ggplot2::ylab('y') +
ggplot2::coord_flip()
```