-
Notifications
You must be signed in to change notification settings - Fork 4
/
Figure1H_Schematic.Rmd
102 lines (86 loc) · 4.68 KB
/
Figure1H_Schematic.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
93
94
95
96
97
98
99
100
101
102
---
title: "RampCodes_Supplemental3"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### ------------------------------------------------------------------------------------------ ###
## Plot example rates from one neuron for schematic in Figure 1H
### ------------------------------------------------------------------------------------------ ###
```{r}
spatial_firing_example <- spatial_firing %>%
filter(Mouse == "M6", Day_numeric == "31", cohort == "3")
```
```{r}
spatial_firing_example <- spatial_firing %>%
filter(lm_group_b == "Negative" & lm_group_b_h == "Negative" & predict_diff > 1 & asr_b_o_rewarded_fit_r.squared >0.9)
```
Function to plot mean and SEM of firing rate as a function of position.
```{r}
position_o = c(0:60)
position_h = c(80:140)
position = c(-29:169)
rates = unlist(unlist(spatial_firing_example$normalised_rates[2]))
#rates = unlist(unlist(spatial_firing_example$Rates_averaged_rewarded_b[1]))
rates_o <- rates[30:90]
rates_h <- rates[110:170]
predict_measured = unlist(unlist(spatial_firing_example$predict_diff[2]))
rates_seg <- mean(rates[110:115])
ggplot() +
geom_line(aes(x=position, y=rates), color = "black", alpha = 0.5, size = 1) +
geom_line(aes(x=position_o, y=rates_o), size = 1) +
geom_smooth(aes(x=position_o, y=rates_o), method = "lm", se = FALSE, color ="red", size = 1, linetype = 'dashed') +
geom_line(aes(x=position_h, y=rates_h), size = 1) +
#geom_smooth(aes(x=position_h, y=rates_h), method = "lm", se = FALSE, color ="red", size = 1) +
geom_segment(aes(x = 80, y = rates_seg, xend = 92, yend = rates_seg), color = "dodgerblue", size=1) +
geom_segment(aes(x = 80, y = rates_seg-predict_measured, xend = 92, yend = rates_seg-predict_measured), color = "dodgerblue", size=1) +
geom_segment(aes(x = 92, y = rates_seg, xend = 92, yend = rates_seg-predict_measured), arrow = arrow(ends='both'), color = "dodgerblue", size=1) +
theme_classic() +
annotate("rect", xmin=-30, xmax=0, ymin=-4,ymax=Inf, alpha=0.2, fill="Grey60") +
annotate("rect", xmin=140, xmax=170, ymin=-4,ymax=Inf, alpha=0.2, fill="Grey60") +
annotate("rect", xmin=60, xmax=80, ymin=-4,ymax=Inf, alpha=0.2, fill="Chartreuse4") +
scale_x_continuous(breaks=seq(-30,170,100), expand = c(0, 0)) +
#scale_y_continuous(breaks=seq(15,60,10), expand = c(0, 0)) +
labs(y = "\nZ-scored firing rate", x = "\nLocation (cm)") +
theme(axis.text.x = element_text(size=18),
axis.text.y = element_text(size=18),
legend.title = element_blank(),
text = element_text(size=18),
plot.margin = margin(21, 25, 5, 20))
ggsave(file = "plots/ExampleZ-score_Shuffled_negneg_eg2.png", width = 4.5, height = 3.5)
```
Function to plot mean and SEM of firing rate as a function of position.
```{r}
position_o = c(0:60)
position_h = c(80:140)
position = c(-29:169)
rates = unlist(unlist(spatial_firing_example$normalised_rates[2]))
#rates = unlist(unlist(spatial_firing_example$Rates_averaged_rewarded_b[1]))
rates_o <- rates[30:90]
rates_h <- rates[110:170]
predict_measured = unlist(unlist(spatial_firing_example$predict_diff[2]))
rates_seg <- mean(rates[110:115])
ggplot() +
geom_line(aes(x=position, y=rates), color = "black", alpha = 0.5, size = 1) +
geom_line(aes(x=position_o, y=rates_o), size = 1) +
geom_smooth(aes(x=position_o, y=rates_o), method = "lm", se = FALSE, color ="red", size = 1, linetype = 'dashed') +
geom_line(aes(x=position_h, y=rates_h), size = 1) +
geom_smooth(aes(x=position_h, y=rates_h), method = "lm", se = FALSE, color ="red", size = 1, linetype = 'dashed') +
#geom_segment(aes(x = 80, y = rates_seg, xend = 92, yend = rates_seg), color = "dodgerblue", size=1) +
#geom_segment(aes(x = 80, y = rates_seg-predict_measured, xend = 92, yend = rates_seg-predict_measured), color = "dodgerblue", size=1) +
#geom_segment(aes(x = 92, y = rates_seg, xend = 92, yend = rates_seg-predict_measured), arrow = arrow(ends='both'), color = "dodgerblue", size=1) +
theme_classic() +
annotate("rect", xmin=-30, xmax=0, ymin=-3,ymax=Inf, alpha=0.2, fill="Grey60") +
annotate("rect", xmin=140, xmax=170, ymin=-3,ymax=Inf, alpha=0.2, fill="Grey60") +
annotate("rect", xmin=60, xmax=80, ymin=-3,ymax=Inf, alpha=0.2, fill="Chartreuse4") +
scale_x_continuous(breaks=seq(-30,170,100), expand = c(0, 0)) +
#scale_y_continuous(breaks=seq(15,60,10), expand = c(0, 0)) +
labs(y = "\nZ-scored firing rate", x = "\nLocation (cm)") +
theme(axis.text.x = element_text(size=18),
axis.text.y = element_text(size=18),
legend.title = element_blank(),
text = element_text(size=18),
plot.margin = margin(21, 25, 5, 20))
ggsave(file = "plots/ExampleZ-score_Shuffled_negneg_eg2_2.png", width = 4.5, height = 3.5)
```