# Question 11: USGS Earthquake API

# Earthquakes of magnitude 5 or higher in October 2025
url <- "https://earthquake.usgs.gov/fdsnws/event/1/query?format=csv&starttime=2025-10-01&endtime=2025-10-31T23:59:59.999&minmagnitude=5&eventtype=earthquake"

# Read the data from the API
earthquakes <- read.csv(url)

# Show the first six rows
head(earthquakes)
##                       time latitude longitude   depth mag magType nst gap
## 1 2025-10-31T21:27:48.004Z   7.0627  127.1014  10.000 5.1      mb  63  51
## 2 2025-10-31T21:21:08.242Z   6.1102  127.2399  35.000 5.0      mb  55  51
## 3 2025-10-31T20:53:24.349Z -45.2902   96.8417   8.000 5.9     mww 288  27
## 4 2025-10-31T19:30:18.479Z -59.5973  -26.3589 109.830 5.2      mb 168  26
## 5 2025-10-31T17:56:41.556Z -23.4330  179.9604 529.356 5.4     mww 261  17
## 6 2025-10-30T17:33:14.566Z  59.6308 -150.2328  23.600 5.4      ml  NA  NA
##     dmin  rms net           id                  updated
## 1  1.511 1.22  us   us6000rkup 2026-01-27T17:59:04.040Z
## 2  1.905 1.43  us   us6000rkum 2026-01-27T17:59:03.040Z
## 3 18.465 0.55  us   us6000rktg 2026-01-27T17:59:03.040Z
## 4  7.679 0.56  us   us6000rksu 2026-01-27T17:59:03.040Z
## 5  5.934 0.68  us   us6000rkpc 2026-01-27T17:59:03.040Z
## 6     NA 0.79  ak ak025dxe5mlz 2026-10-30T17:43:27.505Z
##                                    place       type horizontalError depthError
## 1     63 km ESE of Santiago, Philippines earthquake            6.53      1.792
## 2 120 km ESE of Pondaguitan, Philippines earthquake            6.49      1.876
## 3                 southeast Indian Ridge earthquake            9.41      1.682
## 4          South Sandwich Islands region earthquake           10.88      4.464
## 5              south of the Fiji Islands earthquake           10.66      5.082
## 6         48 km ESE of Fox River, Alaska earthquake              NA      0.300
##   magError magNst   status locationSource magSource
## 1    0.046    153 reviewed             us        us
## 2    0.060     89 reviewed             us        us
## 3    0.054     33 reviewed             us        us
## 4    0.050    132 reviewed             us        us
## 5    0.110      8 reviewed             us        us
## 6       NA     NA reviewed             ak        ak
# Count the number of earthquakes
nrow(earthquakes)
## [1] 178
# Summarize the magnitudes
summary(earthquakes$mag)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   5.000   5.100   5.200   5.351   5.500   7.600
# Plot the earthquake magnitudes
plot(earthquakes$mag,
     main = "Earthquake Magnitudes",
     xlab = "Earthquake Number",
     ylab = "Magnitude")