tokami / TropFishR

Tropical Fisheries Analysis with R
24 stars 19 forks source link

Plotting raw catch frequencies #19

Closed yterzi closed 6 years ago

yterzi commented 6 years ago

Hi. Firstly thanks for the package! I am new on R and also TropFishR. I am trying to arrange my data to plot raw catch frequencies. Here is the code I wrote. When run it I get the error message below. What am I missing?

library(TropFishR)

sample.no <- seq(1,9)
dates <- as.Date(c("2017-06-21","2017-07-25","2017-08-22","2017-09-26"))
midLengths <- seq(3.5,11.5,1)
catch <- c(
        ## 2017-06-21
        0,12,15,0,0,0,0,0,0,  
        ## 2017-07-25
        0,0,11,13,4,0,0,0,1,
        ## 2017-08-22
        0,0,0,0,14,12,6,0,0,
        ## 2017-09-26
        0,0,3,3,6,15,9,0,0)

catch <- matrix(catch,9,4)
colnames(catch) <- c(17.4166667,17.5,17.5833333,17.6666667)

sc <- list(sample.no,midLengths,dates,catch)
names(sc)<- c("sample.no","midLengths","dates","catch")
attr(sc,"catch")="lfq"
plot(sc, Fname = "catch")
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'
marchtaylor commented 6 years ago

Thanks for the encouragement! You were very close with your example script. You just need to change one line where you define the class of sc:

library(TropFishR)

sample.no <- seq(1,9)
dates <- as.Date(c("2017-06-21","2017-07-25","2017-08-22","2017-09-26"))
midLengths <- seq(3.5,11.5,1)
catch <- c(
        ## 2017-06-21
        0,12,15,0,0,0,0,0,0,  
        ## 2017-07-25
        0,0,11,13,4,0,0,0,1,
        ## 2017-08-22
        0,0,0,0,14,12,6,0,0,
        ## 2017-09-26
        0,0,3,3,6,15,9,0,0)

catch <- matrix(catch,9,4)
colnames(catch) <- c(17.4166667,17.5,17.5833333,17.6666667)

sc <- list(sample.no,midLengths,dates,catch)
names(sc)<- c("sample.no","midLengths","dates","catch")

class(sc) <- "lfq" # Here is where you define to class to the whole list, not just an attribute

plot(sc, Fname = "catch")

We will soon be adding a tutorial to help with exactly these kind of data entry issues.

yterzi commented 6 years ago

Thanks for the help. It's a good opinion to prepare a tutorial on data entry. It will be very handy for a new beginner like me.