Repository navigation
Expand file tree
/
Copy pathLandscapes.Rmd
More file actions
171 lines (137 loc) · 6 KB
/
Copy pathLandscapes.Rmd
File metadata and controls
171 lines (137 loc) · 6 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
title: "Landscapes"
author: "Matt Nolan"
date: "26/03/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
set.seed(1)
```
```{r, warning=FALSE}
landscape <- tibble(x = seq(0, 20, length=1000), y = dnorm(x, mean=10, sd=3) * -1, cell = rbinom(n = length(x), size = 1, prob = (y^8/min(y)^8)/25))
(landscape_plot <- ggplot(landscape, aes(x,y)) +
geom_line() +
geom_point(aes(size = ifelse(cell==0, NA, cell))) +
theme_void() +
theme(legend.position="none"))
(landscape_plot_2 <- landscape_plot +
geom_segment(aes(x = 10,y = -0.152,xend = 10,yend = -0.142), arrow = arrow(length = unit(0.1, "inches"))) +
draw_label("Fixed set point", 5, 0.01) +
ylim(-0.16,0.02))
(landscape_plot_3 <- landscape_plot +
geom_segment(aes(x = 10, y = -0.162,xend = 10,yend = -0.147), arrow = arrow(length = unit(0.1, "inches"))) +
ylim(-0.18,0.02))
```
```{r, warning=FALSE}
landscapes <- tibble(x = seq(0, 30, length=3000),
y1 = dnorm(x, mean=10, sd=3) * -1,
cell1 = rbinom(n = length(x), size = 1, prob = (y1^8/min(y1)^8)/25),
y2 = dnorm(x, mean=20, sd=3) * -1,
cell2 = rbinom(n = length(x), size = 1, prob = (y2^8/min(y2)^8)/25))
(landscapes_plot <- ggplot(landscapes) +
geom_line(aes(x, y1)) +
geom_point(aes(x, y1, size = ifelse(cell1==0, NA, cell1)), shape = 5) +
geom_line(aes(x,y2)) +
geom_point(aes(x, y2, size = ifelse(cell2==0, NA, cell2)), shape = 6) +
theme_void() +
theme(legend.position="none"))
(landscapes_plot_2 <- landscapes_plot +
geom_segment(aes(x = 10,y = -0.152,xend = 10,yend = -0.142), arrow = arrow(length = unit(0.1, "inches"))) +
geom_segment(aes(x = 20,y = -0.152,xend = 20,yend = -0.142), arrow = arrow(length = unit(0.1, "inches"))) +
draw_label("Variable set point", 10, 0.01) +
ylim(-0.16,0.02))
(landscapes_plot_3 <- landscapes_plot +
geom_segment(aes(x = 10,y = -0.167,xend = 10,yend = -0.152), arrow = arrow(length = unit(0.1, "inches"))) +
geom_segment(aes(x = 20,y = -0.167,xend = 20,yend = -0.152), arrow = arrow(length = unit(0.1, "inches"))) +
draw_label("Variable", 10, 0.02) +
ylim(-0.18,0.02))
num_reps = 10
seq_length = 3000
landscapes_multiple <- tibble(x = rep(seq(0, 30, length=seq_length), num_reps),
reps = rep(1:num_reps, each = seq_length),
reps_fac = as.factor(reps),
y = dnorm(x, mean=9 + reps, sd=3) * -1,
cell = rbinom(n = seq_length * num_reps, size = 1, prob = (y^8/min(y)^8)/25))
(landscapes_m_plot <- ggplot() +
geom_line(data = landscapes_multiple, aes(x,y, colour = reps_fac)) +
#scale_colour_brewer(direction = -1)
scale_colour_hue(h = c(180,270))
)
arrow_coords <- tibble(x = c(9 + 1:num_reps), y = c(rep(-0.152, num_reps)), xend = c(9 + 1:num_reps), yend = c(rep(-0.137, num_reps)))
(landscapes_m_plot_2 <- landscapes_m_plot +
geom_segment(data = arrow_coords, aes(x = x, y = y, xend = xend, yend = yend), arrow = arrow(length = unit(0.1, "inches"))) +
theme_void() +
theme(legend.position="none") +
ylim(-0.18,0.02))
```
```{r, warning=FALSE}
ggdraw() +
draw_plot(landscape_plot, 0.05, 0, 0.4, 0.9) +
draw_plot(landscapes_plot, 0.55, 0, 0.4, 0.9) +
draw_plot_label(c("A", "B"), c(0, 0.5), c(1,1), size = 24) +
draw_plot_label(c("Fixed set point", "Variable set point"), c(0.05, 0.5), c(0.98,0.98), size = 18)
```
```{r, warning=FALSE}
ggdraw() +
draw_plot(landscape_plot_2, 0.05, 0, 0.4, 1) +
draw_plot(landscapes_plot_2, 0.55, 0, 0.4, 1) +
draw_plot_label(c("A", "B"), c(0, 0.5), c(0.97,0.97), size = 24)
```
```{r, warning=FALSE}
num_cells <- 4
length_plot <- 6000
landscapes_4 <- tibble(x = rep(seq(0, 60, length=length_plot), num_cells),
setpoint_pos = c(rep(10, length_plot), rep(20, length_plot), rep(25, length_plot), rep(50, length_plot)),
y = dnorm(x, mean=setpoint_pos, sd=3) * -1,
cell_prob = rbinom(n = length(x), size = 1, prob = y^2))
ggplot(landscapes_4) + geom_line(aes(x, y, colour = as.factor(setpoint_pos))) +
geom_point(aes(x, y, size = ifelse(cell_prob==0, NA, cell_prob), colour = as.factor(setpoint_pos))) +
theme_void() +
theme(legend.position="none")
```
```{r}
dvplot <- function(tb, ylabel = "Gradient factor", line_palette = "Reds") {
ggplot(tb) +
geom_segment(aes(x = x, y = y, xend = xend, yend = yend, colour = group)) +
xlim(0,1) +
ylim(0,1) +
xlab("Location") +
ylab (ylabel) +
theme(axis.text=element_blank(),
axis.ticks=element_blank(),
legend.position = "none") +
scale_colour_brewer(type = "seq", palette = line_palette)
}
num_cases <- 15
slope_lines <- tibble(x = rep(0,num_cases),
y = rep(1,num_cases),
xend = rep(1,num_cases),
yend = seq(0.2, 0.8, length.out = num_cases),
group = as.factor(1:num_cases))
(sl_plot <- dvplot(slope_lines))
h_lines <- tibble(x = rep(0,num_cases),
y = seq(0.2, 0.6, length.out = num_cases),
xend = rep(1,num_cases),
yend = seq(0.2, 0.6, length.out = num_cases),
group = as.factor(1:num_cases))
(h_plot <- dvplot(h_lines, "Unifrom factor", "Blues"))
setpoint <- tibble(x = rep(0,num_cases),
y = runif(num_cases, 0.6, 1),
xend = rep(1,num_cases),
yend = runif(num_cases, 0.2, 0.6),
group = as.factor(1:num_cases))
(sp_plot <- dvplot(setpoint, "Set point", "Greens"))
```
```{r}
ggdraw() +
draw_plot(landscape_plot_2, 0.05, 0.5, 0.3, 0.5) +
draw_plot(landscapes_plot_2, 0.05, 0, 0.3, 0.5) +
draw_plot(sl_plot, 0.45, 0.5, 0.25, 0.4) +
draw_plot(h_plot, 0.45, 0, 0.25, 0.4) +
draw_plot(sp_plot, 0.75, 0.25, 0.25, 0.4) +
draw_plot_label(c("A", "B" ,"C", "X"), c(0, 0, 0.42, 0.7), c(1,0.5, 1, 0.5), size = c(24,24,24,18))
```
```{r}
ggsave("Figures/Landscape_figure.png", width = 220, height = 140, units = "mm")
```