Earthquake-R-Analysis

Earthquake Visualization & Analysis

A comprehensive R script that fetches global earthquake data (M ≥ 2.5 over the past 30 days) from the USGS and generates a suite of 15 exploratory and analytical plots, including mapping, distributional summaries, time-series, heatmaps, and a regression analysis.

Table of Contents

  1. Project Overview
  2. Features & Plots
  3. Prerequisites
  4. Installation
  5. Usage
  6. Script Breakdown
  7. Interpreting the Outputs
  8. Extending & Customizing
  9. Data Source & Citations
  10. License

Project Overview

This project provides a single, self-contained R script (Earthquake.R) that:

All plots display in sequence when you run the script in R (or RStudio). Ideal for researchers, data analysts, or enthusiasts who want a quick, reproducible overview of recent seismic activity.

Features & Plots

  1. Epicenter Map

    • Size and color scaled by magnitude
  2. Depth‐Colored Map

    • Points shaded by earthquake depth
  3. Magnitude Histogram
  4. Magnitude Density Plot
  5. Depth Histogram
  6. Depth by Magnitude Category (Boxplot)
  7. Magnitude vs. Depth (LOESS smoothing)
  8. Daily Quake Counts (Time-series)
  9. Weekly Hourly Heatmap
  10. Cumulative Quake Count
  11. Top 10 Reported Locations (Bar chart)
  12. Magnitude by Weekday (Violin plot)
  13. Faceted Epicenter Map (By magnitude category)
  14. (Repeated placeholder for consistency – see #13)
  15. Regression Analysis

    • Linear model of mag ~ depth
    • Prints summary (coefficients, R², p-values)
    • Scatter plot with regression line & annotation

and more…

Prerequisites

R Packages

The script will automatically install any missing packages.

Installation

  1. Clone or download this repository to your local machine.
  2. Ensure you have R installed. If using RStudio, open the project there.

No additional dependencies or build steps are required.

Usage

  1. Open R or RStudio.
  2. Set your working directory to the project folder:

    setwd("path/to/project")
    
  3. Source or run the script:

    source("Earthquake.R")
    

    or open the file in the RStudio editor and click “Run All”.

  4. Watch the console output print the regression summary, and view each of the 15 plots in sequence.

Script Breakdown

  1. Setup

    • Defines package list and auto-installs missing ones
    • Loads all libraries
  2. Data Fetch & Preparation

    • Downloads 2.5_month.csv from USGS
    • Parses time to POSIXct and derives date, hour, weekday
    • Bins magnitudes into categories and extracts top 10 “places”
  3. Plotting Sections

    • 2–3: Two world‐map visualizations
    • 4–7: Distribution and relationship plots (histograms, density, boxplot, scatter)
    • 8–10: Time‐based analyses (daily counts, heatmap, cumulative)
    • 11–12: Categorical summaries (bar chart of top locations, violin by weekday)
    • 13: Faceted spatial view by magnitude bin
    • 15: Regression of magnitude on depth with summary and annotated plot

Each plot is constructed with ggplot2 and printed via print(), ensuring they render in non-interactive R consoles or RMarkdown.

Interpreting the Outputs

Extending & Customizing

Data Source & Citations

License

This project is distributed under the MIT License. See LICENSE for full terms.