---
title: "Myo10 Roseplots"
date: 12-07-23
author: Julia Shangguan
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(readr)
library(stringr)
library(dplyr)
library(readxl)
library(ggplot2)

library(plotly)
library(tidyr)
library(scales)

library(geomtextpath)

```



# High signal north: Plotting average molecules per section
```{r}

# Import data
mean_ver = read_csv('HighSignalNorth_MeanMolecules.csv')

mean_ver$lower = mean_ver$Molecules- mean_ver$`SE Molecules`
mean_ver$upper = mean_ver$Molecules + mean_ver$`SE Molecules`

mean_ver$molratio = mean_ver$Molecules/mean_ver$Spots

```


```{r}
# Plot high north Molecules with SE

maxx <- 24000
brk <- seq(0, maxx, by = 4000)

brk1 <- brk[seq(3, length(brk)-1, by = 1)]

ggplot(mean_ver, aes(x = newAngle, y = Molecules, fill = Molecules)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
  #geom_hline(yintercept = seq(0, 12000, by = max(mean_ver$Molecules)/5), colour = "grey92", size = 0.2) +
  geom_hline(yintercept = seq(0, maxx, by = 2000), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(maxx-1, maxx, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x,\(x) bquote(.(x)~degree))) ) + # add degree symbol

  geom_errorbar(aes(ymin =  lower, ymax = upper), position = position_dodge(), width=10, size = 0.3) +
  scale_fill_gradient(low="blue", high="pink") +

  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20)
        ) +
  annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
expand_limits(y = c(0, maxx+2500))
  

```




```{r}

# Plot high north Puncta with SE

brk <- seq(0, 8, by = 1)

brk1 <- brk[seq(6, length(brk)-1, by = 1)]

ggplot(mean_ver, aes(x = newAngle, y = Spots, fill = Spots)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
  #geom_hline(yintercept = seq(0, 8, by = max(mean_ver$Spots)/5), colour = "grey92", size = 0.2) +
  geom_hline(yintercept = seq(0, 8, by = 1), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(7.99, 8, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x, \(x) bquote(.(x)~degree)))) + # add degree symbol

  scale_fill_gradient(low="blue", high="pink") +


  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20),
        ) +
  annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
  expand_limits(y = c(0, 8+0.9)) +
  labs(fill="Puncta")

ggsave("240306_highNorthPuncta.png", width = 5.7, height = 4)
```



```{r}

# Plot high north Molecules/Puncta with SE

maxx1 <- 3600

brk <- seq(0, maxx1, by = 600)

brk1 <- brk[seq(4, length(brk)-1, by = 1)]

ggplot(mean_ver, aes(x = newAngle, y = molratio, fill = molratio)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
  #geom_hline(yintercept = seq(0, 1800, by = max(mean_ver$molratio)/5), colour = "grey92", size = 0.2) +
  geom_hline(yintercept = seq(0, maxx1, by = 300), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(maxx1-1, maxx1, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x, \(x) bquote(.(x)~degree)))) + # add degree symbol

  scale_fill_gradient(low="blue", high="pink") +

  geom_errorbar(aes(ymin =  lower/mean_ver$Spots, ymax = upper/mean_ver$Spots), position = position_dodge(), width=10, size = 0.3) +
  
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20),
        ) +
  annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
  expand_limits(y = c(0, maxx1+450)) +
  labs(fill="Molecules per \npunctum")

```


# Low signal north: Plotting average molecules per section
```{r}
low_mean_ver = read_csv('LowSignalNorth_MeanMolecules.csv')

low_mean_ver$lower = low_mean_ver$Molecules - low_mean_ver$`SE Molecules`
low_mean_ver$upper = low_mean_ver$Molecules + low_mean_ver$`SE Molecules`
low_mean_ver$molratio = low_mean_ver$Molecules/low_mean_ver$Spots

```

```{r}
# Plot low north Molecules with SE

maxx2 <- 9200
brk <- seq(0, maxx2, by = 1000)

brk1 <- brk[seq(7, length(brk)-1, by = 1)]


ggplot(low_mean_ver, aes(x = newAngle, y = Molecules, fill = Molecules)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
 # geom_hline(yintercept = seq(0, 5000, by = max(low_mean_ver$Molecules)/5), colour = "grey92", size = 0.2) +
  geom_hline(yintercept = seq(0, maxx2, by = 1000), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(maxx2-1, maxx2, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x, \(x) bquote(.(x)~degree)))) + # add degree symbol

  geom_errorbar(aes(ymin =  lower, ymax = upper), position = position_dodge(), width=10, size = 0.3) +
  scale_fill_gradient(low="blue", high="pink") +

  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20),
        ) +
    annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
  expand_limits(y = c(0, maxx2+920)) 

```




```{r}
# Plot low north Puncta with SE

brk <- seq(0, 6, by = 0.5)

brk1 <- brk[seq(9, length(brk)-1, by = 2)]

ggplot(low_mean_ver, aes(x = newAngle, y = Spots, fill = Spots)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
 # geom_hline(yintercept = seq(0, 6, by = max(low_mean_ver$Spots)/5), colour = "grey92", size = 0.2) +
  geom_hline(yintercept = seq(0, 6, by = 0.5), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(5.99, 6, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x, \(x) bquote(.(x)~degree)))) + # add degree symbol

  scale_fill_gradient(low="blue", high="pink") +

  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20),
        ) +
  expand_limits(y = c(0, 6+0.7)) +
  annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
  labs(fill="Puncta")

```


```{r}
# Plot low north Molecules/Puncta with SE

maxx3 <- 2600
brk <- seq(0, maxx3, by = 200)

brk1 <- brk[seq(11, length(brk)-1, by = 1)]

ggplot(low_mean_ver, aes(x = newAngle, y = molratio, fill = molratio)) +
  # making grid lines of plot
  geom_vline(xintercept = seq(0, 359, by = 45), colour = "grey92", size = 0.2) +
  #geom_hline(yintercept = seq(0, 1200, by = max(low_mean_ver$molratio)/5), colour = "grey92", size = 0.2) +
  
  geom_hline(yintercept = seq(0, maxx3, by = 200), colour = "grey92", size = 0.2) +

  #darker outer ring
  geom_hline(yintercept = seq(maxx3-1, maxx3, by = 1), colour = "black", size = 0.2) +

  
  geom_bar(stat = "identity", color = "black", size = 0.2) +
  #coord_curvedpolar(clip ="off",theta = "x", start = -0.15708, direction = 1) + # 1/2 width of bar is 18 deg = 0.15708 radians

  coord_polar(theta = "x", start = -0.15708, direction = 1, clip = "off") + 
  #scale_y_continuous(breaks = 0:nlevels(mean_ver$Molecules)) +
  scale_x_continuous(breaks = seq(0, 360, by = 45), labels = ~as.expression(sapply(.x, \(x) bquote(.(x)~degree)))) + # add degree symbol

  scale_fill_gradient(low="blue", high="pink") +

  geom_errorbar(aes(ymin =  lower/low_mean_ver$Spots, ymax = upper/low_mean_ver$Spots), position = position_dodge(), width=10, size = 0.3) +
  
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        panel.border = element_blank(),
        axis.text.x = element_text(size = 20, color = "black"),
        legend.text = element_text(size = 20),
        legend.title = element_text(size = 20)
        ) +
  expand_limits(y = c(0, maxx3+330)) +
  annotate('text', x = 180, y = brk1, label = as.character(signif(brk1, digits = 5)), angle = 0, color = "grey55") +
  labs(fill="Molecules per \npunctum")
 
```