Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4003344
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:08:28+00:00 2026-05-20T08:08:28+00:00

The pre-installed quakes dataset has 5 variables and 1000 observations. The simple graph I’m

  • 0

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 earthquake depth category (i.e. Y-axis = Magnitude , X-axis = Depth Categories).

In this dataset, the earthquake depth variables range from 40 to 680. I would like to turn the 1000 observations of earthquake depth into 8 categories, e.g. 40 – 120, 121 – 200, … 600 – 680. Then, I’d like to take the average earthquake magnitude by depth category and plot it on a line chart.

I appreciate any help with this.
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:08:29+00:00Added an answer on May 20, 2026 at 8:08 am

    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()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the simple pre-installed code snippets in VS2008. I can insert
Mac OS X 10.6 (Snow Leopard) has VIM pre-installed (version 7.2), which is great.
My web hosting said ImageMagic has been pre-installed on the server. I did a
I want to install a plugins dll to a pre-installed application. Pre-installed application has
I have Mac OS X Snow leopard that has pre-installed Ruby 1.8.7 and Rails
Mac OS X ships with apache pre-installed, but the files are in non-standard locations.
Is there some default Windows scripting language that comes pre-installed on XP and Vista
In my existing (Pre-SVN 1.5) merge strategy, we create a copy of the Trunk
Python came pre-installed on my macbook and I have been slowly getting acquainted with
I know that Java is pre-installed in Mac OS X but i wonder if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.