kandi background
Explore Kits

goby | Goby framework and tools for analysis of high-throughput | Genomics library

 by   CampagneLaboratory Java Version: 2.3.2 License: Non-SPDX

 by   CampagneLaboratory Java Version: 2.3.2 License: Non-SPDX

Download this library from

kandi X-RAY | goby Summary

goby is a Java library typically used in Artificial Intelligence, Genomics applications. goby has no bugs, it has no vulnerabilities and it has low support. However goby build file is not available and it has a Non-SPDX License. You can download it from GitHub.
Goby is a next-gen data management framework designed to facilitate the implementation of efficient data analysis pipelines. The program is distributed under the GNU General Public License (GPL).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • goby has a low active ecosystem.
  • It has 17 star(s) with 2 fork(s). There are 6 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 2 open issues and 4 have been closed. On average issues are closed in 34 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of goby is 2.3.2
goby Support
Best in #Genomics
Average in #Genomics
goby Support
Best in #Genomics
Average in #Genomics

quality kandi Quality

  • goby has no bugs reported.
goby Quality
Best in #Genomics
Average in #Genomics
goby Quality
Best in #Genomics
Average in #Genomics

securitySecurity

  • goby has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
goby Security
Best in #Genomics
Average in #Genomics
goby Security
Best in #Genomics
Average in #Genomics

license License

  • goby has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
goby License
Best in #Genomics
Average in #Genomics
goby License
Best in #Genomics
Average in #Genomics

buildReuse

  • goby releases are available to install and integrate.
  • goby has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
goby Reuse
Best in #Genomics
Average in #Genomics
goby Reuse
Best in #Genomics
Average in #Genomics
Top functions reviewed by kandi - BETA

kandi has reviewed goby and discovered the below as its top functions. This is intended to give you an instant insight into goby implemented functionality, and help decide if they suit your requirements.

  • Writes the annotation counts .
    • Combine multiple input files
      • Decodes and returns the aligned alignment entry .
        • Parse the current line .
          • Build a record for an annotation
            • Process a read .
              • Observe counts .
                • Displays a compact file .
                  • Compare the atoms in the given range .
                    • Rearches an index entry and updates the score .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      goby Key Features

                      Goby framework and tools for analysis of high-throughput sequencing data

                      Source code

                      copy iconCopydownload iconDownload
                      git clone git://github.com/CampagneLaboratory/goby.git
                      cd goby
                      git checkout stable (adjust the version number as needed, or use stable for the latest stable branch)
                      

                      Row names column can't be removed in R

                      copy iconCopydownload iconDownload
                      Usage:
                      
                           write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
                                       eol = "\n", na = "NA", dec = ".", row.names = TRUE,
                                       col.names = TRUE, qmethod = c("escape", "double"),
                                       fileEncoding = "")
                           
                           write.csv(...)
                           write.csv2(...)
                      
                      Arguments:
                      
                         ...
                      
                      row.names: either a logical value indicating whether the row names of
                                'x' are to be written along with 'x', or a character vector
                                of row names to be written.
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(dat,splist[run])  
                        mapply(write.csv, x=dataList, file=filenameVal[run], row.names=FALSE) # CHANGE
                        print(paste(run,splist[run]))
                      }
                      
                      write.csv(iris[1:3,])
                      # "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # "1",5.1,3.5,1.4,0.2,"setosa"
                      # "2",4.9,3,1.4,0.2,"setosa"
                      # "3",4.7,3.2,1.3,0.2,"setosa"
                      
                      write.csv(iris[1:3,], row.names=FALSE)
                      # "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # 5.1,3.5,1.4,0.2,"setosa"
                      # 4.9,3,1.4,0.2,"setosa"
                      # 4.7,3.2,1.3,0.2,"setosa"
                      
                      Usage:
                      
                           write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
                                       eol = "\n", na = "NA", dec = ".", row.names = TRUE,
                                       col.names = TRUE, qmethod = c("escape", "double"),
                                       fileEncoding = "")
                           
                           write.csv(...)
                           write.csv2(...)
                      
                      Arguments:
                      
                         ...
                      
                      row.names: either a logical value indicating whether the row names of
                                'x' are to be written along with 'x', or a character vector
                                of row names to be written.
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(dat,splist[run])  
                        mapply(write.csv, x=dataList, file=filenameVal[run], row.names=FALSE) # CHANGE
                        print(paste(run,splist[run]))
                      }
                      
                      write.csv(iris[1:3,])
                      # "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # "1",5.1,3.5,1.4,0.2,"setosa"
                      # "2",4.9,3,1.4,0.2,"setosa"
                      # "3",4.7,3.2,1.3,0.2,"setosa"
                      
                      write.csv(iris[1:3,], row.names=FALSE)
                      # "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # 5.1,3.5,1.4,0.2,"setosa"
                      # 4.9,3,1.4,0.2,"setosa"
                      # 4.7,3.2,1.3,0.2,"setosa"
                      
                      Usage:
                      
                           write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
                                       eol = "\n", na = "NA", dec = ".", row.names = TRUE,
                                       col.names = TRUE, qmethod = c("escape", "double"),
                                       fileEncoding = "")
                           
                           write.csv(...)
                           write.csv2(...)
                      
                      Arguments:
                      
                         ...
                      
                      row.names: either a logical value indicating whether the row names of
                                'x' are to be written along with 'x', or a character vector
                                of row names to be written.
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(dat,splist[run])  
                        mapply(write.csv, x=dataList, file=filenameVal[run], row.names=FALSE) # CHANGE
                        print(paste(run,splist[run]))
                      }
                      
                      write.csv(iris[1:3,])
                      # "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # "1",5.1,3.5,1.4,0.2,"setosa"
                      # "2",4.9,3,1.4,0.2,"setosa"
                      # "3",4.7,3.2,1.3,0.2,"setosa"
                      
                      write.csv(iris[1:3,], row.names=FALSE)
                      # "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # 5.1,3.5,1.4,0.2,"setosa"
                      # 4.9,3,1.4,0.2,"setosa"
                      # 4.7,3.2,1.3,0.2,"setosa"
                      

                      Automating a ggplot for each level in a group

                      copy iconCopydownload iconDownload
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      
                      library(tidyverse) ###!!!###
                      data
                      
                      GetMatrix=function(data, commonToSum) {
                        newdat<-filter(data,common_name %in% commonToSum)
                        cdata2 <- plyr::ddply(data, c("year", "season"), summarise,
                                              N    = length(num),
                                              n_mean = mean(num),
                                              n_median = median(num),
                                              sd   = sd(num),
                                              se   = sd / sqrt(N))
                        cdata2$year_season <- paste(cdata2$year, "_", cdata2$season, sep = "")
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'wet'] <- 2005.75)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'wet'] <- 2006.75)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'wet'] <- 2007.75)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'wet'] <- 2008.75)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'wet'] <- 2009.75)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'wet'] <- 2010.75)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'wet'] <- 2011.75)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'wet'] <- 2012.75)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'wet'] <- 2013.75)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'wet'] <- 2014.75)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'wet'] <- 2015.75)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'wet'] <- 2016.75)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'wet'] <- 2017.75)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'wet'] <- 2018.75)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'wet'] <- 2019.75)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'wet'] <- 2020.75)
                        cdata2 <- within(cdata2, year[year == 2005 & season == 'dry'] <- 2005.25)
                        cdata2 <- within(cdata2, year[year == 2006 & season == 'dry'] <- 2006.25)
                        cdata2 <- within(cdata2, year[year == 2007 & season == 'dry'] <- 2007.25)
                        cdata2 <- within(cdata2, year[year == 2008 & season == 'dry'] <- 2008.25)
                        cdata2 <- within(cdata2, year[year == 2009 & season == 'dry'] <- 2009.25)
                        cdata2 <- within(cdata2, year[year == 2010 & season == 'dry'] <- 2010.25)
                        cdata2 <- within(cdata2, year[year == 2011 & season == 'dry'] <- 2011.25)
                        cdata2 <- within(cdata2, year[year == 2012 & season == 'dry'] <- 2012.25)
                        cdata2 <- within(cdata2, year[year == 2013 & season == 'dry'] <- 2013.25)
                        cdata2 <- within(cdata2, year[year == 2014 & season == 'dry'] <- 2014.25)
                        cdata2 <- within(cdata2, year[year == 2015 & season == 'dry'] <- 2015.25)
                        cdata2 <- within(cdata2, year[year == 2016 & season == 'dry'] <- 2016.25)
                        cdata2 <- within(cdata2, year[year == 2017 & season == 'dry'] <- 2017.25)
                        cdata2 <- within(cdata2, year[year == 2018 & season == 'dry'] <- 2018.25)
                        cdata2 <- within(cdata2, year[year == 2019 & season == 'dry'] <- 2019.25)
                        cdata2 <- within(cdata2, year[year == 2020 & season == 'dry'] <- 2020.25)
                        cdata2  ###The function has to return something###
                      }
                      
                      
                      
                      Plot<-function(data,common_name,fileName=NULL) {
                        ###I changed ggplot(cdata2,... to ggplot(data,...
                        ggplot(data, aes(x = year, y = n_mean, color = season)) +
                          annotate(geom = "rect", xmin = 2010, xmax = 2010.5, ymin = -Inf, ymax = Inf,
                                   fill = "lightblue", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2013.5, xmax = 2014, ymin = -Inf, ymax = Inf,
                                   fill = "lightgreen", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2017.5, xmax = 2018, ymin = -Inf, ymax = Inf,
                                   fill = "#E0E0E0", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2011.5, xmax = 2012, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2015.5, xmax = 2016, ymin = -Inf, ymax = Inf,
                                   fill = "pink", colour = NA, alpha = 0.4) +
                          annotate(geom = "rect", xmin = 2018.5, xmax = 2019, ymin = -Inf, ymax = Inf,
                                   fill = "orange", colour = NA, alpha = 0.4) +
                          geom_errorbar(aes(ymin=n_mean-se, ymax=n_mean+se), 
                                        width=.2, 
                                        color = "black") +
                          geom_point(color = "black", 
                                     shape = 21, 
                                     size = 3,
                                     aes(fill = season)) +
                          scale_fill_manual(values=c("white", "#C0C0C0")) +   scale_x_continuous(breaks=c(2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2018,2019,2020)) +
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))
                        
                      }
                      
                      spSummary <- data %>%
                        group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      
                      
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist),splist,"- IBBEAM_trend_plot.png")
                      
                      setwd('C:/Users/...Trend plots')
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(data,splist[run])
                        Plot(data=dataList[[run]],splist[run],fileName=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      
                      
                      GetSummary = function(data) data %>%
                        mutate(year = year+ifelse(season=='wet',0.75,0.25)) %>%
                        group_by(year, season) %>%
                        summarise(
                          .groups = "keep",
                          N = n(),
                          n_mean = mean(num),
                          n_median = median(num),
                          sd   = sd(num),
                          se   = sd / sqrt(N)
                        )
                      
                      library(tidyverse)
                      data = data %>% 
                        as_tibble() %>%
                        mutate(common_name = common_name %>% fct_infreq() %>% fct_drop()) %>%
                        group_by(common_name) %>% 
                        nest() %>%
                        mutate(summ = map(data, GetSummary))
                      data
                      #  A tibble: 3 x 3
                      #  Groups:   common_name [3]
                      #  common_name         data              summ                
                      #  <fct>               <list>            <list>              
                      #1 Hardhead Silverside <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #2 Mojarra spp         <tibble [30 x 4]> <grouped_df [6 x 7]>
                      #3 Rainwater Killifish <tibble [30 x 4]> <grouped_df [6 x 7]>
                      
                      data[1,]$summ
                      #  A tibble: 6 x 7
                      #  Groups:   year, season [6]
                      #   year season     N n_mean n_median    sd    se
                      #  <dbl> <fct>  <int>  <dbl>    <int> <dbl> <dbl>
                      #1 2018. dry        5    0.8        0  1.79  0.8 
                      #2 2019. wet        5    5          0 11.2   5   
                      #3 2019. dry        5    2          0  4.47  2   
                      #4 2020. wet        5   13.2        0 29.5  13.2 
                      #5 2020. dry        5    0          0  0     0   
                      #6 2021. wet        5    3.6        0  6.99  3.12
                      
                      dfAnnot = tribble(
                        ~year,     ~fill,
                        2010,   "lightblue",
                        2011.5, "pink",
                        2013.5, "lightgreen",
                        2015.5, "pink",
                        2017.5, "#E0E0E0",
                        2018.5, "orange"
                      )
                      
                      makePlot = function(df, group, dir=""){
                        data = df$summ[[1]]
                        plot = data %>% ggplot(aes(year, n_mean, fill=season))+
                          geom_point(color = "black", shape = 21, size = 3)+
                          geom_errorbar(aes(ymin = n_mean-se, ymax = n_mean+se), width = .2)+
                          annotate(xmin = dfAnnot$year, xmax = dfAnnot$year+0.5,
                                   ymin = -Inf, ymax = Inf, fill = dfAnnot$fill,
                                   geom="rect", alpha = 0.4) +
                          scale_fill_manual(values=c("white", "#C0C0C0"))+
                          scale_x_continuous(breaks=2005:2020)+
                          theme(panel.border = element_rect(fill = NA, color = "black"),
                                panel.background = element_blank(),
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank()) +
                          labs(x="Year", y = "Mean count") +
                          theme(plot.title = element_text(hjust = 0.5)) +
                          theme(axis.text.y = element_text(size = 10, face = "bold")) +
                          theme(axis.text.x = element_text(size = 10, face = "bold")) +
                          theme(axis.title = element_text(size = 14, face = "bold"))+
                          ggtitle(group$common_name)
                        ggsave(paste(dir, group$common_name,".png"), plot)
                        plot
                      }
                      
                      data %>% group_by(common_name) %>%
                        group_map(makePlot, dir="plots/")
                      

                      Automatically make time series plots for each level in a group

                      copy iconCopydownload iconDownload
                      library(tidyverse)
                      plots <-
                        data %>%
                        nest(-common_name) %>%
                        mutate(
                          plt = data %>% map(possibly(~ {
                            .x %>%
                              ggplot(aes(year, num, color = site)) +
                                geom_point()
                          }, NA))
                        ) %>%
                        select(common_name, plt) %>%
                        deframe()
                      
                      plots[["Mojarra spp"]]
                      plots[["Rainwater Killifish"]]
                      
                      allspecies <- unique(data$common_name)
                      
                      for(species in allspecies){
                      
                          ## insert your code here
                          
                          ggsave(paste0(species, ".png"))
                      }
                      

                      Projectiles Image Error Problem How To FIx?

                      copy iconCopydownload iconDownload
                      class projectile(object):
                        def __init__(self, x, y,color):
                            # [...]
                      
                      bullets.append(
                         projectile(
                             round(playerman.x+playerman.width//2),
                             round(playerman.y + playerman.height//2),
                             6,
                             (0,0,0)))
                      
                      class projectile(object):
                         def __init__(self,x,y,radius,color):
                             # [...]
                      
                      bullets.append(
                          projectile(
                              round(playerman.x+playerman.width//2),
                              round(playerman.y + playerman.height//2),
                              (0,0,0)))
                      
                      class projectile(object):
                        def __init__(self, x, y,color):
                            # [...]
                      
                      bullets.append(
                         projectile(
                             round(playerman.x+playerman.width//2),
                             round(playerman.y + playerman.height//2),
                             6,
                             (0,0,0)))
                      
                      class projectile(object):
                         def __init__(self,x,y,radius,color):
                             # [...]
                      
                      bullets.append(
                          projectile(
                              round(playerman.x+playerman.width//2),
                              round(playerman.y + playerman.height//2),
                              (0,0,0)))
                      
                      class projectile(object):
                        def __init__(self, x, y,color):
                            # [...]
                      
                      bullets.append(
                         projectile(
                             round(playerman.x+playerman.width//2),
                             round(playerman.y + playerman.height//2),
                             6,
                             (0,0,0)))
                      
                      class projectile(object):
                         def __init__(self,x,y,radius,color):
                             # [...]
                      
                      bullets.append(
                          projectile(
                              round(playerman.x+playerman.width//2),
                              round(playerman.y + playerman.height//2),
                              (0,0,0)))
                      
                      class projectile(object):
                        def __init__(self, x, y,color):
                            # [...]
                      
                      bullets.append(
                         projectile(
                             round(playerman.x+playerman.width//2),
                             round(playerman.y + playerman.height//2),
                             6,
                             (0,0,0)))
                      
                      class projectile(object):
                         def __init__(self,x,y,radius,color):
                             # [...]
                      
                      bullets.append(
                          projectile(
                              round(playerman.x+playerman.width//2),
                              round(playerman.y + playerman.height//2),
                              (0,0,0)))
                      

                      Community Discussions

                      Trending Discussions on goby
                      • Row names column can't be removed in R
                      • Automating a ggplot for each level in a group
                      • Automatically make time series plots for each level in a group
                      • Projectiles Image Error Problem How To FIx?
                      Trending Discussions on goby

                      QUESTION

                      Row names column can't be removed in R

                      Asked 2022-Jan-26 at 22:05

                      I have a function that transforms a dataframe's structure (making each value for "year_season" factor as its own column) for each value in a list (a list of species names) and reorders the 1st column values (the location or "site") to be in order (low to high). I then tell it to save the dataframe as a matrix and print each matrix as a csv. For some reason though, the function is making a another column out of the rownames and I can't remove it.

                      data = "dat":

                      > dat[sample(nrow(dat), 5), ] #Selects 5 random rows of data
                             site year_season            common_name num
                      171930   41    2016_wet     Longsnout Seahorse   0
                      110012   18    2012_wet                Tomtate   5
                      2594     24    2005_dry                  Porgy   0
                      90037    28    2011_dry Florida Grassflat Crab   1
                      5444     41    2005_dry              Code Goby   2
                      

                      Transformed data (a matrix like this for each species):

                      enter image description here

                      # Summarize total counts by species common_name
                      spSummary <- dat %>% group_by(common_name) %>%
                        dplyr::summarize(total.numbers=sum(num)) %>%
                        arrange(-total.numbers)
                      spSummary
                      
                      splist<-spSummary$common_name
                      dataList<-list()
                      filenameVal<-paste0(1:length(splist), splist, " - my_matrix.csv")
                      
                      GetMatrix=function(data,spToSum) {
                        newdat<-filter(data,common_name %in% spToSum)
                        matrixdat<-dcast(newdat, site ~ year_season, value.var="num", fun.aggregate = sum, fill=NA)
                        matrixdat$site <- as.character(matrixdat$site)
                        matrixdat <- matrixdat[order(nchar(matrixdat$site), matrixdat$site)]
                        matrixdat <- as.matrix(matrixdat[,-1]) # This removes "site"
                      }
                      
                      
                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(dat,splist[run])  
                        mapply(write.csv, x=dataList, file=filenameVal[run])
                        print(paste(run,splist[run]))
                      }
                      

                      This is an example of one of the csv files with this 1st column that I can't get rid of...

                      enter image description here

                      ANSWER

                      Answered 2022-Jan-26 at 22:05

                      That's the default functionality of write.table and write.csv. Add row.names=FALSE. From ?write.csv:

                      Usage:
                      
                           write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
                                       eol = "\n", na = "NA", dec = ".", row.names = TRUE,
                                       col.names = TRUE, qmethod = c("escape", "double"),
                                       fileEncoding = "")
                           
                           write.csv(...)
                           write.csv2(...)
                      
                      Arguments:
                      
                         ...
                      
                      row.names: either a logical value indicating whether the row names of
                                'x' are to be written along with 'x', or a character vector
                                of row names to be written.
                      

                      Update your for loop as:

                      for(run in 1:length(splist)) {
                        dataList[[run]]<-GetMatrix(dat,splist[run])  
                        mapply(write.csv, x=dataList, file=filenameVal[run], row.names=FALSE) # CHANGE
                        print(paste(run,splist[run]))
                      }
                      

                      Demo with real data:

                      write.csv(iris[1:3,])
                      # "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # "1",5.1,3.5,1.4,0.2,"setosa"
                      # "2",4.9,3,1.4,0.2,"setosa"
                      # "3",4.7,3.2,1.3,0.2,"setosa"
                      
                      write.csv(iris[1:3,], row.names=FALSE)
                      # "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
                      # 5.1,3.5,1.4,0.2,"setosa"
                      # 4.9,3,1.4,0.2,"setosa"
                      # 4.7,3.2,1.3,0.2,"setosa"
                      

                      Source https://stackoverflow.com/questions/70870804

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install goby

                      You can download it from GitHub.
                      You can use goby like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the goby component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      You will find extensive documentation at goby.campagnelab.org. Questions and feedback should be addressed to the Goby user forum.

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Genomics Libraries
                      Try Top Libraries by CampagneLaboratory
                      Compare Genomics Libraries with Highest Support
                      Compare Genomics Libraries with Highest Quality
                      Compare Genomics Libraries with Highest Security
                      Compare Genomics Libraries with Permissive License
                      Compare Genomics Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.