###Overall goal is to calculate and plot (both histogram and time series) CPUE of the most commonly caught fish in the dataset. #CPUE = # of individuals / angler / hour #Each data point is a trip #Basic strategy # 1) Calculate average frequency of fish being caught by species over all trips and find the max -- this is the most commonly caught species. # 2) Calulate CPUE (#fish angler-1 hr-1) for that species for each trip # 3) Make histogram (CPUE on x-axis and frequency on y-axis) # 4) Split data by port and make scatter plot (with date on x-axis, CPUE on y-axis). Pretty the plot with titles and a legend. ######################## # Set up: ######################## # Clear the workspace #set working directory (or use a project) #load data #Convert Date column in tripData to Date class for plotting (cleaner) #Convert TripNum, DropNum, SpeciesCode to factors (why?) ######################## # Step 1: calculate most commonly caught species ######################## #Make data frame of counts for each species by trip; use table() which creates a contingency table #convert to data frame which is easier to work with (for me at least) #Use tapply to calculate the mean number caught for each species over all trips #sort in decending order #now add names from speciesCode data frame using merge #get the species codes which as stored as column names; use names() #grab only species that are in our data set -- find using match() #assemble into new data frame #print top five species for visual inspection ######################### # Step 2: For the most common species calculate CPUE ######################## #pull out the most common species. This is the first row of our sorted vector 'codes' #run table() again and store as data frame #Merge with tripData data frame #Calculate CPUE, note units ######################### # Step 3: Plot histogram ######################## # Define title for plots (you can do this directly in the plot command also) # Advanced: pluck common and scientific name from data sets and paste() together for a title #Make historgam of CPUE ######################### # Step 4: Make scatter plot ######################## #split dataset into Morro Bay and San Luis #define colors for plot #Make scatter plot with title and axis labels # Add points #Add legend #DONE!