Loading custom theme function
library(ggplot2)
methodsTheme =
function(font = NA, base_size = 12){
theme(
#Text font
text = element_text(family = font, size = base_size),
#Color
line = element_line(color = "black"),
panel.background = element_rect(fill = "white"), #fill plot background
legend.key = element_rect(fill = "white"), #fill background of legend key
axis.line = element_line(color = "black"), #color axes lines
#Positioning
legend.position = "right", #change legend position
#options: none, left, right, bottom, top
#Text sizes and options
plot.title = element_text(
size = base_size*1.3, #title size
face = "plain"), #options: plain, italic, bold, bold.italic
axis.title = element_text(size = base_size), #axis titles text size
axis.text = element_text(size = base_size, color = "black"), #axis labels/tick numbers text size
legend.text = element_text(size = base_size), #legend text size
legend.title = element_text(size = base_size) #legend title text size
)
}
Tidy data
library(tidyr)
d1 <- pivot_longer(df_raw,
cols = "Chaetognath":"Snail",
names_to = "Species",
values_to = "Count")
glimpse(d1)
## Rows: 648
## Columns: 4
## $ Station <chr> "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT",…
## $ Sample <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ Species <chr> "Chaetognath", "Copepod", "Cope. Nauplii", "Lucifer", "Mysid",…
## $ Count <int> 0, 141, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
d2 <- d1 %>%
dplyr::group_by(Station, Sample, Species) %>%
dplyr::summarize(Total_Count = sum(Count))
## `summarise()` has grouped output by 'Station', 'Sample'. You can override using
## the `.groups` argument.
glimpse(d2)
## Rows: 216
## Columns: 4
## Groups: Station, Sample [9]
## $ Station <chr> "MID", "MID", "MID", "MID", "MID", "MID", "MID", "MID", "M…
## $ Sample <int> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5…
## $ Species <chr> "Amphipods", "Brittle star", "Chaetognath", "Cnidarian Lar…
## $ Total_Count <int> 0, 0, 246, 0, 25, 235, 1, 11, 43, 0, 0, 90, 0, 12, 12, 75,…
df <- d2