The pre-installed quakes dataset has 5 variables and 1000 observations.
The simple graph I\'m trying to create should show the average earthquake magnitude by earth
First classify into depth classes with cut:
depth.class <- cut(quakes$depth, c(40, 120, 200, 300, 400, 500, 600, 680), include.lowest = TRUE)
(Note that your class definitions may need to vary for exactly what you are after and given the details of cut()'s behaviour).
Find the mean magnitude within each depth.class (assumes no NAs):
mean.mag <- tapply(quake$mag, depth.class, mean)
(Add na.rm e.g. mean.mag <- tapply(quake$mag, depth.class, mean, na.rm = TRUE) for data sets with missing values where appropriate).
Plot as a line:
plot(mean.mag, type = "l", xlab = "magnitude class")
It's a little extra work to put the class labels on the X-axis, but at that point you might question if a line plot is really appropriate here.
A quick stab, turn off the axes and then put up the classes directly from the cut factor:
plot(mean.mag, type = "l", xlab = "magnitude class", axes = FALSE)
axis(1, 1:nlevels(depth.class), levels(depth.class))
axis(2)
box()