0

first time posting on here so I'm sorry if I've missed something. I'm currently using code from my old boss, who said I would simply have to put the new csv into the existing script and everything should run smoothly. This has not been the case. My goal is to have graphs produced for each fish species, comparing wet weight and total length to check for outliers. When I run the script, it doesn't flag any errors yet it is not producing the graphs. Any help would be greatly appreciated, and I am able to provide anymore details you guys might need.

fishid<- read.csv(file="2018_fishidcheck.csv", header=T, na.strings = "NA")
fish<- read.csv(file="fish_2019_qaqc.csv", header=T, na.strings = "NA")
fish$FishID<-as.numeric(fish$FishID)

#create subset of fish (by species) to sample for both aging structures, based on size class
data1<- subset(fish, select = c(Common,FishID,TLmm))
data2<-subset(data1, !is.na(data1$FishID))
data2 <- transform(data2, bin = cut(TLmm, 17.5))
write.csv(data2, file = "fish_id_TL.csv")


#check for outliers in length-weight - 
SPClist <- unique(fish$Common)
#omit species that have only NA for WetWt 
#SPClist<-SPClist[-(32)] 


#Create a graph for each species by running through the species list
for(i in SPClist){

#Create a data subset for the species you'd like to create a boxplot for:
mydataSPC <- subset(fish, Common == i, select = 

c(ProjectID,ProjName,ProjType,ProjectID1,Effst,SiteID,Area,SampDate,
                      NameAbbrev, Common, LifeStage, FishID,TLmm, WetWT))


#Create a WetvsTL linear graphs for the species:
plotSPC = plot(WetWT~TLmm,data=mydataSPC, xlab = "Length (mm)", ylab =         
"Weight Wet (g)")
title((paste("Wetwt vs TL for species",i,"Individual Fish data")), 
cex.main = 0.75) 
text(mydataSPC$TLmm, mydataSPC$WetWT, mydataSPC$FishID, cex=0.6, pos=3, 
offset=0.4, col="red")

#Export the plot as a .jpg:
dev.copy(jpeg, filename= (paste(i,".jpg")))
dev.off();
}

EDIT TO INCLUDE A BIT OF DATA

Common  FishID  TLmm    bin
35  Common Shiner   30  116 (114,137]
36  Common Shiner   31  96  (89.8,114]
37  Common Shiner   32  112 (89.8,114]
38  Common Shiner   33  96  (89.8,114]
39  Yellow Perch    34  248 (232,256]
40  Yellow Perch    35  226 (209,232]
41  Yellow Perch    36  208 (185,209]
42  Yellow Perch    37  207 (185,209]
43  Yellow Perch    38  204 (185,209]
58  Yellow Perch    15  177 (161,185]
59  Yellow Perch    16  213 (209,232]
60  White Sucker    17  291 (280,304]
64  Yellow Perch    18  245 (232,256]
65  Yellow Perch    19  197 (185,209]
123 Yellow Perch    46  165 (161,185]
124 White Sucker    47  226 (209,232]
125 White Sucker    48  226 (209,232]
126 White Sucker    49  200 (185,209]
127 White Sucker    50  228 (209,232]
129 White Sucker    20  470 (446,470]
Ashlie
  • 1
  • 2
  • Thanks for producing the code, but can you also provide a dozen rows of data? Or something similar? – akash87 Dec 12 '19 at 18:20
  • 2
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. We can't run your code without any data. Also note the *minimal* part in [mcve]—to help debug, we probably don't need to write csv files. First step in debugging is often isolating just the parts directly related to the problem – camille Dec 12 '19 at 18:30
  • @akash87 I have included a bit of data – Ashlie Dec 12 '19 at 19:02
  • Try resetting your directory: use `getwd()` and `setwd()` – akash87 Dec 12 '19 at 19:04
  • @akash87 I've done this and it's still not outputting the graphs "setwd("C:/Users/Public/Documents/MAES/data/BiologicalData/FishComm/2019")" – Ashlie Dec 12 '19 at 19:06
  • Check to see if one subset of the data actually produces a graph without exporting, if it does produce then it is an issue with the filename or export, if it doesn't then it is an issue with your data. – akash87 Dec 12 '19 at 19:43
  • At the top of your code there are two csv files. It's not clear which data the sample data corresponds to. Could you please clarify, or provide two bits of sample data? Also, please consider using the dput() function to provide us with an easy way to copy/paste your data. – xilliam Dec 12 '19 at 21:42

0 Answers0