0

I need to create a scatterplot showing how the abundances of the 12 most common species vary with depth.

How do I use the scatter.smooth() function in order to create the twelve separate graphs of the twelve species?

My biggest issue right now is being able to pick out just those twelve species and their mean abundances and depth from the data.

I found this about the scatter.smooth() function:

scatter.smooth(x, y = NULL, span = 2/3, degree = 1,
    family = c("symmetric", "gaussian"),
    xlab = NULL, ylab = NULL,
    ylim = range(y, pred$y, na.rm = TRUE),
    evaluation = 50, …, lpars = list())

But, I don't understand how to pick out the twelve species from my data and not include all 200+ species.

I need to transform the data by taking the square root of the counts. To do that do I just use: sqrt(df$y) ?

I thought of trying something like this:

with(ReefFish, scatter.smooth(sqrt(count), depth))

And I got a graph with lots of warnings but it also is just doing count for all species instead of a separate graph for all twelve species.

Is there a way to make a loop of that code for the twelve specific species?

I tried something like this with no luck:

species.to.use
[1] "Vanderbilt's chromis"
[2] "Agile chromis"
[3] "Brown surgeonfish"
[4] "Spotted surgeonfish"
[5] "Yellow tang"
[6] "Common bluestripe snapper"
[7] "Arc-eye hawkfish"
[8] "Hawaiian bicolor chromis"
[9] "Whitebar surgeonfish"
[10] "Saddle wrasse"
[11] "Striated wrasse"
[12] "Pebbled butterflyfish"

par(mfrow = c(3,4))
for (i in 1:12) {
 scatter = subset(ReefFish, commonname == species.to.use[i])

 with(scatter, scatter.smooth(sqrt(count), depth), type = 'b', pch = 
19, main = species.to.use[i])
}

I can't figure out how to define the species I want to be used in the code.

  • How do you use `scatter.smooth` function for 1 species? What is `x` and `y` ? – Ronak Shah Sep 15 '21 at 12:19
  • I am plotting for 12 species. X and Y are count and depth. I need to plot a scatterplot of count vs. depth using the top 12 species based on their mean abundance which I figured out using tapply. – Alison Meeth Sep 15 '21 at 12:21
  • I can't figure out how to define the 12 species that I want to use in the for loop. – Alison Meeth Sep 15 '21 at 12:23
  • So out of 200 species you want to select only 12 of them? Which 12 species you want to include? Is it based on sim of counts ? – Ronak Shah Sep 15 '21 at 13:11
  • It's the top 12 with the highest mean abundance which are: "Vanderbilt's chromis", "Agile chromis", "Brown surgeonfish", "Spotted surgeonfish", "Yellow tang", "Common bluestripe snapper", "Arc-eye hawkfish", "Hawaiian bicolor chromis", "Whitebar surgeonfish", "Saddle wrasse", "Striated wrasse", "Pebbled butterflyfish" – Alison Meeth Sep 15 '21 at 13:13
  • Like this ? `scatter = subset(ReefFish, commonname %in% species.to.use)` – Ronak Shah Sep 15 '21 at 13:19
  • I think so but it says "species.to.use" isn't defined yet so I think the error is somewhere in the beginning when I'm trying to say what species I want to use. – Alison Meeth Sep 15 '21 at 13:21

0 Answers0