Importing data

df_raw = read.csv("plankton1.csv", strip.white = TRUE, check.names = FALSE)

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

A

library(ggplot2)
se <- function(x) sd(x) / sqrt(length(x)) # Create own function

df_A <- df %>%
  dplyr::group_by(Species) %>%
  dplyr::summarize(
    mean_abund = mean(Total_Count),
    se_abund = se(Total_Count)
  ) %>%
  arrange(desc(mean_abund))

plot_A <- ggplot(
  df_A,
  aes(x = Species, y = mean_abund)
) +
  geom_bar(stat = "identity", 
           position = "dodge",
           fill = "gray70",
           width = 0.5) +
  geom_errorbar(aes(ymin = mean_abund - se_abund, 
                    ymax = mean_abund + se_abund), 
                position = position_dodge(width = 0.9), 
                width = 0.25) +
  scale_y_continuous(expand = c(0, 0)) +
  labs(x = "Species", y = "Abundance") +
  methodsTheme() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
plot_A