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
Are you sure that you want a line plot here? I'm not sure that is the most appropriate plot to use here. Regardless, the trick here is to use cut to bin the data appropriately, and then use one of the many aggregation tools to find the average magnitude by those groups. Finally, we'll plot those aggregated values. I like the tools in ggplot2 and plyr for tasks like this:
library(ggplot2)
df <- quakes
df$bins <- with(df, cut(depth, breaks = c(0,40, 120, 200, 280, 360, 440, 520, 600, 680)))
df.plot <- ddply(df, .(bins), summarise, avg.mag = mean(mag))
qplot(bins, avg.mag, data = df.plot)
#If you want a line plot, here's one approach:
qplot(as.numeric(bins), avg.mag, data = df.plot, geom = "line") +
xlim(levels(df.plot$bins))