---
# System prepended metadata

title: R study (Pyramid plot)

---

# R study (Pyramid plot)

## Pyramid plot drawing

:::            info

This is the method to create pyramid plot to distribute gene proportion of B. carinata subgenomes. These plots were produced with R-studio and statements are described as follows. 
:::

---


## R-studio statement

### Turn on the required libraries
```r=
library(readxl)
library(ggplot2)
library(ggthemes)
library(forcats)
library(dplyr)
```
### Turn off scientific notations like 1e+40
```r=
options(scipen = 999)  
```
### Load raw data
```r=
df<-read_excel("dfdf.xlsx")
```

### Create the gene_content plot 
```r=
df %>% 
    mutate(Assembly = fct_reorder(Assembly, Order)) %>%
    ggplot(aes(x = Percentage_of_gene_content_in_each_genome, y = Assembly, fill = Subgenome)) + 
    geom_bar(stat = "identity", width = .5) +
    scale_x_continuous(breaks=seq(-60,60,10),labels=abs(seq(-60,60,10))) +
    scale_fill_brewer(palette = "Dark2") + 
    theme_grey() + 
    theme(axis.line = element_line(colour = "black")) +
    labs(x="Percentage of gene content in each genome", y="Assembly", fill="Subgenome") + 
    expand_limits(x=c(-65,65))
```






### Create genome_size plot 
```r=
df %>% 
    mutate(Assembly = fct_reorder(Assembly, Order)) %>%
    ggplot(aes(x = Percentage_of_genome_size_in_each_genome, y = Assembly, fill = Subgenome)) + 
    geom_bar(stat = "identity", width = .5) +
    scale_x_continuous(breaks=seq(-60,60,10),labels=abs(seq(-60,60,10))) +
    scale_fill_brewer(palette = "Dark2") + 
    theme_grey() + 
    theme(axis.line = element_line(colour = "black")) +
    labs(x="Percentage of genome size in each genome", y="Assembly", fill="Subgenome") + 
    expand_limits(x=c(-65,65))
```    
![img](https://i.imgur.com/tBA4uUu.png)


### Facet grid plot
```r=
df %>% 
    mutate(Assembly = fct_reorder(Assembly, Order)) %>%
    ggplot(aes(x = Xaxis, y = Assembly, fill = Subgenome)) + 
    geom_bar(stat = "identity", width = .5) +    scale_x_continuous(breaks=seq(-60,60,10),labels=abs(seq(-60,60,10))) +
    scale_fill_brewer(palette = "Dark2") + 
    theme_grey() + 
    theme(axis.line = element_line(colour = "black")) +
    labs(x="Xaxis", y="Assembly", fill="Subgenome") + 
    expand_limits(x=c(-65,65)) + facet_grid(cols=vars(Facet))
```



### Save as PDF
```r= 
ggsave("Pyramid.pdf", width = 8, height=6)
```

---

### Reference
-- http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html
-- https://www.r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
-- https://stackoverflow.com/questions/10861773/remove-grid-background-color-and-top-and-right-borders-from-ggplot2

### input file

### Individual pyramid plot
[Download link](https://pastebin.com/dnrSA80W) 

| Order | Taxonomy          | Assembly       | Sub          | Subgenome | Percentage_of_gene_content_in_each_genome | Percentage_of_genome_size_in_each_genome |
|-------|-------------------|----------------|--------------|-----------|-------------------------------------------|------------------------------------------|
| 1     | Brassica carinata | Gomenzer       | BC subgenome | Left      | -54.3                                     | -52.39                                   |
| 1     | Brassica carinata | Gomenzer       | Cc subgenome | Right     | 45.7                                      | 47.61                                    |
| 2     | Brassica carinata | ZD-1           | BC subgenome | Left      | -41.75                                    | -45.37                                   |
| 2     | Brassica carinata | ZD-1           | Cc subgenome | Right     | 58.25                                     | 54.63                                    |
| 3     | Brassica juncea   | T8466_v1       | Aj subgenome | Left      | -50.53                                    | -47.57                                   |
| 3     | Brassica juncea   | T8466_v1       | Bj subgenome | Right     | 49.47                                     | 52.43                                    |
| 4     | Brassica juncea   | Varuna         | Aj subgenome | Left      | -45.49                                    | -38.54                                   |
| 4     | Brassica juncea   | Varuna         | Bj subgenome | Right     | 54.51                                     | 61.46                                    |
| 5     | Brassica napus    | Darmor-bzh V5  | An subgenome | Left      | -44.23                                    | -38.42                                   |
| 5     | Brassica napus    | Darmor-bzh V5  | Cn subgenome | Right     | 55.77                                     | 61.58                                    |
| 6     | Brassica napus    | Darmor-bzh V10 | An subgenome | Left      | -44.15                                    | -39.32                                   |
| 6     | Brassica napus    | Darmor-bzh V10 | Cn subgenome | Right     | 55.85                                     | 60.68                                    |
| 7     | Brassica napus    | Express617     | An subgenome | Left      | -46.86                                    | -38.66                                   |
| 7     | Brassica napus    | Express617     | Cn subgenome | Right     | 53.14                                     | 61.34                                    |
| 8     | Brassica napus    | GanganF73      | An subgenome | Left      | -45.95                                    | -41.32                                   |
| 8     | Brassica napus    | GanganF73      | Cn subgenome | Right     | 54.05                                     | 58.68                                    |
| 9     | Brassica napus    | No2127         | An subgenome | Left      | -45.53                                    | -40.75                                   |
| 9     | Brassica napus    | No2127         | Cn subgenome | Right     | 54.47                                     | 59.25                                    |
| 10    | Brassica napus    | QuintaA        | An subgenome | Left      | -45.2                                     | -40.48                                   |
| 10    | Brassica napus    | QuintaA        | Cn subgenome | Right     | 54.8                                      | 59.52                                    |
| 11    | Brassica napus    | Shengli3       | An subgenome | Left      | -46.68                                    | -41.25                                   |
| 11    | Brassica napus    | Shengli3       | Cn subgenome | Right     | 53.32                                     | 58.75                                    |
| 12    | Brassica napus    | Tapidor3       | An subgenome | Left      | -45.14                                    | -40.81                                   |
| 12    | Brassica napus    | Tapidor3       | Cn subgenome | Right     | 54.86                                     | 59.19                                    |
| 13    | Brassica napus    | Westar         | An subgenome | Left      | -45.87                                    | -41.14                                   |
| 13    | Brassica napus    | Westar         | Cn subgenome | Right     | 54.13                                     | 58.86                                    |
| 14    | Brassica napus    | Zheyou73       | An subgenome | Left      | -46.57                                    | -40.98                                   |
| 14    | Brassica napus    | Zheyou73       | Cn subgenome | Right     | 53.43                                     | 59.02                                    |
| 15    | Brassica napus    | Zs11           | An subgenome | Left      | -45.77                                    | -40.79                                   |
| 15    | Brassica napus    | Zs11           | Cn subgenome | Right     | 54.23                                     | 59.21                                    |



#### Facet_grid

| Facet | Order | Taxonomy          | Assembly       | Sub          | Subgenome | Xaxis  |
|-------|-------|-------------------|----------------|--------------|-----------|--------|
| 1     | 1     | Brassica carinata | Gomenzer       | BC subgenome | Left      | -54.3  |
| 1     | 1     | Brassica carinata | Gomenzer       | Cc subgenome | Right     | 45.7   |
| 1     | 2     | Brassica carinata | ZD-1           | BC subgenome | Left      | -41.75 |
| 1     | 2     | Brassica carinata | ZD-1           | Cc subgenome | Right     | 58.25  |
| 1     | 3     | Brassica juncea   | T8466_v1       | Aj subgenome | Left      | -50.53 |
| 1     | 3     | Brassica juncea   | T8466_v1       | Bj subgenome | Right     | 49.47  |
| 1     | 4     | Brassica juncea   | Varuna         | Aj subgenome | Left      | -45.49 |
| 1     | 4     | Brassica juncea   | Varuna         | Bj subgenome | Right     | 54.51  |
| 1     | 5     | Brassica napus    | Darmor-bzh V5  | An subgenome | Left      | -44.23 |
| 1     | 5     | Brassica napus    | Darmor-bzh V5  | Cn subgenome | Right     | 55.77  |
| 1     | 6     | Brassica napus    | Darmor-bzh V10 | An subgenome | Left      | -44.15 |
| 1     | 6     | Brassica napus    | Darmor-bzh V10 | Cn subgenome | Right     | 55.85  |
| 1     | 7     | Brassica napus    | Express617     | An subgenome | Left      | -46.86 |
| 1     | 7     | Brassica napus    | Express617     | Cn subgenome | Right     | 53.14  |
| 1     | 8     | Brassica napus    | GanganF73      | An subgenome | Left      | -45.95 |
| 1     | 8     | Brassica napus    | GanganF73      | Cn subgenome | Right     | 54.05  |
| 1     | 9     | Brassica napus    | No2127         | An subgenome | Left      | -45.53 |
| 1     | 9     | Brassica napus    | No2127         | Cn subgenome | Right     | 54.47  |
| 1     | 10    | Brassica napus    | QuintaA        | An subgenome | Left      | -45.2  |
| 1     | 10    | Brassica napus    | QuintaA        | Cn subgenome | Right     | 54.8   |
| 1     | 11    | Brassica napus    | Shengli3       | An subgenome | Left      | -46.68 |
| 1     | 11    | Brassica napus    | Shengli3       | Cn subgenome | Right     | 53.32  |
| 1     | 12    | Brassica napus    | Tapidor3       | An subgenome | Left      | -45.14 |
| 1     | 12    | Brassica napus    | Tapidor3       | Cn subgenome | Right     | 54.86  |
| 1     | 13    | Brassica napus    | Westar         | An subgenome | Left      | -45.87 |
| 1     | 13    | Brassica napus    | Westar         | Cn subgenome | Right     | 54.13  |
| 1     | 14    | Brassica napus    | Zheyou73       | An subgenome | Left      | -46.57 |
| 1     | 14    | Brassica napus    | Zheyou73       | Cn subgenome | Right     | 53.43  |
| 1     | 15    | Brassica napus    | Zs11           | An subgenome | Left      | -45.77 |
| 1     | 15    | Brassica napus    | Zs11           | Cn subgenome | Right     | 54.23  |
| 2     | 1     | Brassica carinata | Gomenzer       | BC subgenome | Left      | -52.39 |
| 2     | 1     | Brassica carinata | Gomenzer       | Cc subgenome | Right     | 47.61  |
| 2     | 2     | Brassica carinata | ZD-1           | BC subgenome | Left      | -45.37 |
| 2     | 2     | Brassica carinata | ZD-1           | Cc subgenome | Right     | 54.63  |
| 2     | 3     | Brassica juncea   | T8466_v1       | Aj subgenome | Left      | -47.57 |
| 2     | 3     | Brassica juncea   | T8466_v1       | Bj subgenome | Right     | 52.43  |
| 2     | 4     | Brassica juncea   | Varuna         | Aj subgenome | Left      | -38.54 |
| 2     | 4     | Brassica juncea   | Varuna         | Bj subgenome | Right     | 61.46  |
| 2     | 5     | Brassica napus    | Darmor-bzh V5  | An subgenome | Left      | -38.42 |
| 2     | 5     | Brassica napus    | Darmor-bzh V5  | Cn subgenome | Right     | 61.58  |
| 2     | 6     | Brassica napus    | Darmor-bzh V10 | An subgenome | Left      | -39.32 |
| 2     | 6     | Brassica napus    | Darmor-bzh V10 | Cn subgenome | Right     | 60.68  |
| 2     | 7     | Brassica napus    | Express617     | An subgenome | Left      | -38.66 |
| 2     | 7     | Brassica napus    | Express617     | Cn subgenome | Right     | 61.34  |
| 2     | 8     | Brassica napus    | GanganF73      | An subgenome | Left      | -41.32 |
| 2     | 8     | Brassica napus    | GanganF73      | Cn subgenome | Right     | 58.68  |
| 2     | 9     | Brassica napus    | No2127         | An subgenome | Left      | -40.75 |
| 2     | 9     | Brassica napus    | No2127         | Cn subgenome | Right     | 59.25  |
| 2     | 10    | Brassica napus    | QuintaA        | An subgenome | Left      | -40.48 |
| 2     | 10    | Brassica napus    | QuintaA        | Cn subgenome | Right     | 59.52  |
| 2     | 11    | Brassica napus    | Shengli3       | An subgenome | Left      | -41.25 |
| 2     | 11    | Brassica napus    | Shengli3       | Cn subgenome | Right     | 58.75  |
| 2     | 12    | Brassica napus    | Tapidor3       | An subgenome | Left      | -40.81 |
| 2     | 12    | Brassica napus    | Tapidor3       | Cn subgenome | Right     | 59.19  |
| 2     | 13    | Brassica napus    | Westar         | An subgenome | Left      | -41.14 |
| 2     | 13    | Brassica napus    | Westar         | Cn subgenome | Right     | 58.86  |
| 2     | 14    | Brassica napus    | Zheyou73       | An subgenome | Left      | -40.98 |
| 2     | 14    | Brassica napus    | Zheyou73       | Cn subgenome | Right     | 59.02  |
| 2     | 15    | Brassica napus    | Zs11           | An subgenome | Left      | -40.79 |
| 2     | 15    | Brassica napus    | Zs11           | Cn subgenome | Right     | 59.21  |