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.