The primary strategy for this Week’s assignment is to capitalize on the maps and mapdata library packages that I learned while working with my Project 3 Team and use the longitude and latitude fields derived from the NY Times’ Geographic API to map workable data sets based on specific queries. I will analyze 3 examples using the NY Times’ Geographic API.
I, first, had to acquire an API key from NY Times per their Developer instructions. Once I got the API key, I had to experiment with different API calls that would fit my homework assignment.
library(stringr)
library(XML)
library(RCurl)
library(rlist)
library(RJSONIO)
library(tidyr)
library(tidyverse)
library(dplyr)
library(ggplot2)
library(knitr)
library(kableExtra)
library(jsonlite)
library(maps)
library(mapdata)
apikey <- "64701cafa953419d97329d4d3b0fb415"
options(knitr.table.format = "html")In this part of the assignment, I retrieved the top 20 geo locations for Canada from the NY Times Geographic API. According to one of the articles by J. Fitzgerald [FIT], it was easy to flatten the JSON result into a workable data frame using the fromJSON method. I displayed my output in kable tabular format. Afterwards, I extracted field values for Name, Longitude, Latitude, Elevation, and Population. For this data set, I chose to display all extracted rows. I displayed the intermediate result in kable tabular format. Using the R map packages, I displayed all data points represented by longitude and latitude to display specific coordinates in the country of Canada.
urladdr <- paste("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?country_code=CA&api-key=",apikey, sep="")
CADataFrame <- fromJSON(urladdr, flatten = TRUE) %>% data.frame()
CADataFrame %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| status | copyright | num_results | results.concept_id | results.concept_name | results.geocode_id | results.geoname_id | results.name | results.latitude | results.longitude | results.elevation | results.population | results.country_code | results.country_name | results.admin_code1 | results.admin_code2 | results.admin_code3 | results.admin_code4 | results.admin_name1 | results.admin_name2 | results.admin_name3 | results.admin_name4 | results.feature_class | results.feature_code | results.feature_code_name | results.time_zone_id | results.dst_offset | results.gmt_offset | results.geocodes_created | results.geocodes_updated |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 28956 | Saskatchewan (Canada) | 7260 | 6141242 | Saskatchewan | 54.00010 | -106.00099 | NA | 1006644 | CA | Canada | 11 | NA | NA | NA | Saskatchewan | NA | NA | NA | A | ADM1 | first-order administrative division | America/Regina | -6 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24760 | Edmonton (Alberta) | 5124 | 5946768 | Edmonton | 53.55014 | -113.46871 | 668 | 712391 | CA | Canada | 01 | NA | NA | NA | Alberta | NA | NA | NA | P | PPL | populated place | America/Edmonton | -6 | -7 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 29968 | Vancouver Island (British Columbia) | 5452 | 6173336 | Vancouver Island | 49.49961 | -125.50289 | NA | NA | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | T | ISL | island | America/Vancouver | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 25308 | Golden (British Columbia) | 5884 | 5962582 | Golden | 51.29995 | -116.96890 | NA | 4038 | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | P | PPL | populated place | America/Edmonton | -6 | -7 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 22600 | Algonquin Provincial Park (Ontario) | 7780 | 5883649 | Algonquin Provincial Park | 45.75012 | -78.49956 | NA | NA | CA | Canada | 08 | NA | NA | NA | Ontario | NA | NA | NA | L | PRK | park | America/Toronto | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 25160 | Galiano Island (British Columbia) | 6492 | 5959084 | Galiano Island | 48.93294 | -123.45265 | NA | NA | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | T | ISL | island | America/Vancouver | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26844 | Manitoba (Canada) | 4632 | 6065171 | Manitoba | 55.00019 | -97.00049 | NA | 1193566 | CA | Canada | 03 | NA | NA | NA | Manitoba | NA | NA | NA | A | ADM1 | first-order administrative division | America/Winnipeg | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27700 | Nunavut (Canada) | 5420 | 6091732 | Nunavut | 70.16784 | -90.73325 | NA | 30776 | CA | Canada | 14 | NA | NA | NA | Nunavut | NA | NA | NA | A | ADM1 | first-order administrative division | America/Resolute | -5 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26436 | Lake Superior | 3760 | 6048728 | Lake Superior | 48.00010 | -86.99997 | NA | NA | CA | Canada | 08 | NA | NA | NA | Ontario | NA | NA | NA | H | LK | lake | America/Nipigon | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26044 | Jasper National Park (Canada) | 6680 | 5985931 | Jasper National Park of Canada | 52.98333 | -118.10238 | NA | NA | CA | Canada | 01 | NA | NA | NA | Alberta | NA | NA | NA | L | RES | reserve | America/Edmonton | -6 | -7 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 30356 | Yarmouth (Nova Scotia) | 7584 | 6185217 | Yarmouth | 43.83345 | -66.11557 | NA | 7500 | CA | Canada | 07 | NA | NA | NA | Nova Scotia | NA | NA | NA | P | PPL | populated place | America/Halifax | -3 | -4 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24220 | Columbia River (Pacific Northwest) | 3812 | 5926219 | Columbia River | 48.99983 | -117.63550 | NA | NA | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | H | STM | stream | America/Vancouver | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 30256 | Whistler (British Columbia) | 2500 | 6180142 | Whistler | 50.11639 | -122.95275 | NA | NA | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | L | AREA | area | America/Vancouver | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23760 | Canada | 116 | 6251999 | Canada | 60.00000 | -96.00000 | NA | 33679000 | CA | Canada | 00 | NA | NA | NA | NA | NA | NA | NA | A | PCLI | independent political entity | America/Rankin_Inlet | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24952 | Fernie (British Columbia) | 6436 | 5952370 | Fernie | 49.49996 | -115.06871 | NA | 5019 | CA | Canada | 02 | NA | NA | NA | British Columbia | NA | NA | NA | P | PPL | populated place | America/Edmonton | -6 | -7 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27564 | Niagara-on-the-Lake (Ontario) | 5736 | 6087905 | Niagara-on-the-Lake | 43.25012 | -79.06627 | NA | NA | CA | Canada | 08 | NA | NA | NA | Ontario | NA | NA | NA | P | PPL | populated place | America/Toronto | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23800 | Cape Breton Island (Canada) | 6128 | 5915569 | Cape Breton Island | 46.16684 | -60.74849 | NA | NA | CA | Canada | 07 | NA | NA | NA | Nova Scotia | NA | NA | NA | T | ISL | island | America/Glace_Bay | -3 | -4 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27540 | Newfoundland (Canada) | 2748 | 6354959 | Newfoundland and Labrador | 52.00000 | -56.00000 | NA | 508099 | CA | Canada | 05 | NA | NA | NA | Newfoundland and Labrador | NA | NA | NA | A | ADM1 | first-order administrative division | America/Blanc-Sablon | -4 | -4 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26352 | Labrador (Canada) | 2748 | 6354959 | Newfoundland and Labrador | 52.00000 | -56.00000 | NA | 508099 | CA | Canada | 05 | NA | NA | NA | Newfoundland and Labrador | NA | NA | NA | A | ADM1 | first-order administrative division | America/Blanc-Sablon | -4 | -4 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27444 | New Brunswick (Canada) | 2716 | 6087430 | New Brunswick | 46.50010 | -65.99878 | NA | 751250 | CA | Canada | 04 | NA | NA | NA | New Brunswick | NA | NA | NA | A | ADM1 | first-order administrative division | America/Moncton | -3 | -4 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
CAsites<-CADataFrame[,8:12]
names(CAsites) <- c("Name","Latitude","Longitude","Elevation","Population")
CAsites %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| Name | Latitude | Longitude | Elevation | Population |
|---|---|---|---|---|
| Saskatchewan | 54.00010 | -106.00099 | NA | 1006644 |
| Edmonton | 53.55014 | -113.46871 | 668 | 712391 |
| Vancouver Island | 49.49961 | -125.50289 | NA | NA |
| Golden | 51.29995 | -116.96890 | NA | 4038 |
| Algonquin Provincial Park | 45.75012 | -78.49956 | NA | NA |
| Galiano Island | 48.93294 | -123.45265 | NA | NA |
| Manitoba | 55.00019 | -97.00049 | NA | 1193566 |
| Nunavut | 70.16784 | -90.73325 | NA | 30776 |
| Lake Superior | 48.00010 | -86.99997 | NA | NA |
| Jasper National Park of Canada | 52.98333 | -118.10238 | NA | NA |
| Yarmouth | 43.83345 | -66.11557 | NA | 7500 |
| Columbia River | 48.99983 | -117.63550 | NA | NA |
| Whistler | 50.11639 | -122.95275 | NA | NA |
| Canada | 60.00000 | -96.00000 | NA | 33679000 |
| Fernie | 49.49996 | -115.06871 | NA | 5019 |
| Niagara-on-the-Lake | 43.25012 | -79.06627 | NA | NA |
| Cape Breton Island | 46.16684 | -60.74849 | NA | NA |
| Newfoundland and Labrador | 52.00000 | -56.00000 | NA | 508099 |
| Newfoundland and Labrador | 52.00000 | -56.00000 | NA | 508099 |
| New Brunswick | 46.50010 | -65.99878 | NA | 751250 |
wm<-map_data("world")
caM<-ggplot() + geom_polygon(data = wm, aes(x=long, y = lat, group = group), fill = NA, color = "black") + coord_fixed(1.5)
caM<-caM+xlim(-135,-45)+ylim(42,75)
caM+geom_point(data=CAsites,aes(x=Longitude,y=Latitude,color="Places"), size=3)+
labs(color="Canada")+theme_bw()In this part of the assignment, I retrieved the top 20 geo locations for Australia from the NY Times Geographic API. According to one of the articles by J. Fitzgerald [FIT], it was easy to flatten the JSON result into a workable data frame using the fromJSON method. I displayed my output in kable tabular format. Afterwards, I extracted field values for Name, Longitude, Latitude, Elevation, and Population. I took a step further by using dplyr:filter to only use rows with populations greater than 300,000. For this data set, I chose to display all extracted rows. I displayed the intermediate result in kable tabular format. Using the R map packages, I displayed all data points represented by longitude and latitude to display specific coordinates in the country of Australia whose populations were greater than 300,000.
urladdr <- paste("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?country_code=AU&api-key=",apikey, sep="")
AUDataFrame <- fromJSON(urladdr, flatten = TRUE) %>% data.frame()
AUDataFrame %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| status | copyright | num_results | results.concept_id | results.concept_name | results.geocode_id | results.geoname_id | results.name | results.latitude | results.longitude | results.elevation | results.population | results.country_code | results.country_name | results.admin_code1 | results.admin_code2 | results.admin_code3 | results.admin_code4 | results.admin_name1 | results.admin_name2 | results.admin_name3 | results.admin_name4 | results.feature_class | results.feature_code | results.feature_code_name | results.time_zone_id | results.dst_offset | results.gmt_offset | results.geocodes_created | results.geocodes_updated |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23824 | Cape Tribulation (Australia) | 6136 | 2146032 | Cape Tribulation | -16.09959 | 145.4604 | NA | NA | AU | Australia | 04 | NA | NA | NA | Queensland | NA | NA | NA | T | CAPE | cape | Australia/Brisbane | 10.0 | 10.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 28104 | Perth (Australia) | 3460 | 2063523 | Perth | -31.93333 | 115.8333 | NA | 1446704 | AU | Australia | 08 | NA | NA | NA | Western Australia | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Perth | 8.0 | 9.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 67820 | County Kilkenny (Ireland) | 8896 | 2077062 | Barrow Island | -20.79785 | 115.4063 | NA | NA | AU | Australia | 08 | NA | NA | NA | Western Australia | NA | NA | NA | T | ISL | island | Australia/Perth | 8.0 | 8.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 29704 | Tiwi Islands | 2092 | 6942032 | Tiwi Islands | -12.36333 | 130.8803 | NA | NA | AU | Australia | 03 | NA | NA | NA | Northern Territory | NA | NA | NA | T | ISL | island | Australia/Darwin | 9.5 | 9.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24500 | Darwin (Australia) | 6340 | 2073124 | Darwin | -12.46113 | 130.8418 | NA | 93080 | AU | Australia | 03 | NA | NA | NA | Northern Territory | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Darwin | 9.5 | 9.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23772 | Canberra (Australia) | 4988 | 2172517 | Canberra | -35.28346 | 149.1281 | NA | 327700 | AU | Australia | 01 | NA | NA | NA | Australian Capital Territory | NA | NA | NA | P | PPLC | capital of a political entity | Australia/Sydney | 10.0 | 11.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 25720 | Hobart (Tasmania) | 5484 | 2163355 | Hobart | -42.91667 | 147.3333 | NA | 47700 | AU | Australia | 06 | NA | NA | NA | Tasmania | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Hobart | 10.0 | 11.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 29528 | Sydney (Australia) | 1412 | 2147714 | Sydney | -33.86785 | 151.2073 | NA | 4394576 | AU | Australia | 02 | NA | NA | NA | New South Wales | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Sydney | 10.0 | 11.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 22948 | Australia | 168 | 2077456 | Australia | -25.00000 | 135.0000 | NA | 20600000 | AU | Australia | 00 | NA | NA | NA | NA | NA | NA | NA | A | PCLI | independent political entity | Australia/Darwin | 9.5 | 9.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 22604 | Alice Springs (Australia) | 5184 | 2077895 | Alice Springs | -23.70000 | 133.8833 | NA | 26188 | AU | Australia | 03 | NA | NA | NA | Northern Territory | NA | NA | NA | P | PPL | populated place | Australia/Darwin | 9.5 | 9.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26964 | Melbourne (Australia) | 1292 | 2158177 | Melbourne | -37.81400 | 144.9633 | NA | 3730206 | AU | Australia | 07 | NA | NA | NA | Victoria | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Melbourne | 10.0 | 11.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23596 | Broome (Australia) | 6096 | 2075720 | Broome | -17.96667 | 122.2333 | NA | 13218 | AU | Australia | 08 | NA | NA | NA | Western Australia | NA | NA | NA | P | PPL | populated place | Australia/Perth | 8.0 | 9.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 25396 | Great Barrier Reef (Australia) | 5800 | 2164628 | Great Barrier Reef | -18.00000 | 146.8333 | NA | NA | AU | Australia | 04 | NA | NA | NA | Queensland | NA | NA | NA | H | RF | reef(s) | None | NA | NA | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23564 | Brisbane (Australia) | 3536 | 2174003 | Brisbane | -27.46794 | 153.0281 | NA | 958504 | AU | Australia | 04 | NA | NA | NA | Queensland | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Brisbane | 10.0 | 10.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 22504 | Adelaide (Australia) | 2864 | 2078025 | Adelaide | -34.93333 | 138.6000 | NA | 1074159 | AU | Australia | 05 | NA | NA | NA | South Australia | NA | NA | NA | P | PPLA | seat of a first-order administrative division | Australia/Adelaide | 9.5 | 10.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 67812 | Cornish (NH) | 8896 | 2077062 | Barrow Island | -20.79785 | 115.4063 | NA | NA | AU | Australia | 08 | NA | NA | NA | Western Australia | NA | NA | NA | T | ISL | island | Australia/Perth | 8.0 | 8.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 29608 | Tasmania (Australia) | 3292 | 2147291 | Tasmania | -42.00000 | 147.0000 | NA | 492700 | AU | Australia | 06 | NA | NA | NA | Tasmania | NA | NA | NA | A | ADM1 | first-order administrative division | Australia/Hobart | 10.0 | 11.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 26872 | Margaret River (Australia) | 6848 | 2066980 | Margaret River | -12.93333 | 131.2500 | NA | NA | AU | Australia | 03 | NA | NA | NA | Northern Territory | NA | NA | NA | H | STM | stream | Australia/Darwin | 9.5 | 9.5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 70472 | Queensland (Australia) | 8148 | 2152274 | Queensland | -20.00000 | 145.0000 | NA | 4264590 | AU | Australia | 04 | NA | NA | NA | Queensland | NA | NA | NA | A | ADM1 | first-order administrative division | Australia/Brisbane | 10.0 | 10.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 67756 | Barrow Island (Australia) | 8896 | 2077062 | Barrow Island | -20.79785 | 115.4063 | NA | NA | AU | Australia | 08 | NA | NA | NA | Western Australia | NA | NA | NA | T | ISL | island | Australia/Perth | 8.0 | 8.0 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
AUsites<-AUDataFrame[,8:12]
names(AUsites) <- c("Name","Latitude","Longitude","Elevation","Population")
AUsites <- filter(AUsites, Population > 300000)
AUsites %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| Name | Latitude | Longitude | Elevation | Population |
|---|---|---|---|---|
| Perth | -31.93333 | 115.8333 | NA | 1446704 |
| Canberra | -35.28346 | 149.1281 | NA | 327700 |
| Sydney | -33.86785 | 151.2073 | NA | 4394576 |
| Australia | -25.00000 | 135.0000 | NA | 20600000 |
| Melbourne | -37.81400 | 144.9633 | NA | 3730206 |
| Brisbane | -27.46794 | 153.0281 | NA | 958504 |
| Adelaide | -34.93333 | 138.6000 | NA | 1074159 |
| Tasmania | -42.00000 | 147.0000 | NA | 492700 |
| Queensland | -20.00000 | 145.0000 | NA | 4264590 |
wm<-map_data("world")
auM<-ggplot() + geom_polygon(data = wm, aes(x=long, y = lat, group = group), fill = NA, color = "black") + coord_fixed(1.5)
auM<-auM+xlim(112,154)+ylim(-45,-10)
auM+geom_point(data=AUsites,aes(x=Longitude,y=Latitude,color="Places"), size=3)+
labs(color="Australia")+theme_bw()In this part of the assignment, I retrieved the top 20 geo locations for the United States from the NY Times Geographic API. According to one of the articles by J. Fitzgerald [FIT], it was easy to flatten the JSON result into a workable data frame using the fromJSON method. I displayed my output in kable tabular format. Afterwards, I extracted field values for Name, Longitude, Latitude, Elevation, and Population. I took a step further by using dplyr:filter to only use rows with populations greater than 30,000 and elevations greater than 100. For this data set, I chose to display all extracted rows. I displayed the intermediate result in kable tabular format. Using the R map packages, I displayed all data points represented by longitude and latitude to display specific coordinates in the country of United States whose populations were greater than 30,000 and whose elevations are greater than 100.
urladdr <- paste("http://api.nytimes.com/svc/semantic/v2/geocodes/query.json?country_code=US&api-key=",apikey, sep="")
USDataFrame <- fromJSON(urladdr, flatten = TRUE) %>% data.frame()
USDataFrame %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| status | copyright | num_results | results.concept_id | results.concept_name | results.geocode_id | results.geoname_id | results.name | results.latitude | results.longitude | results.elevation | results.population | results.country_code | results.country_name | results.admin_code1 | results.admin_code2 | results.admin_code3 | results.admin_code4 | results.admin_name1 | results.admin_name2 | results.admin_name3 | results.admin_name4 | results.feature_class | results.feature_code | results.feature_code_name | results.time_zone_id | results.dst_offset | results.gmt_offset | results.geocodes_created | results.geocodes_updated |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24012 | Charlottesville (Va) | 2840 | 4752031 | Charlottesville | 38.02931 | -78.47668 | 142 | 34703 | US | United States | VA | 540 | NA | NA | Virginia | City of Charlottesville | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 28132 | Philadelphia (Pa) | 436 | 4560349 | Philadelphia | 39.95233 | -75.16379 | 12 | 1517550 | US | United States | PA | 101 | NA | NA | Pennsylvania | Philadelphia County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 28848 | San Juan National Forest (Colo) | 7240 | 5437675 | San Juan National Forest | 37.69166 | -107.80895 | 3472 | NA | US | United States | CO | 111 | NA | NA | Colorado | San Juan County | NA | NA | V | FRST | forest(s) | America/Shiprock | -6 | -7 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27356 | Nantucket (Mass) | 1312 | 4944903 | Nantucket | 41.28346 | -70.09946 | 13 | 14775 | US | United States | MA | 019 | NA | NA | Massachusetts | Nantucket County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 71052 | Yamhill (Ore) | 8680 | 5761959 | Yamhill | 45.34150 | -123.18733 | 60 | 1024 | US | United States | OR | 071 | NA | NA | Oregon | Yamhill County | NA | NA | P | PPL | populated place | America/Los_Angeles | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27744 | Ohio River | 3916 | 4401696 | Ohio River | 36.98672 | -89.13062 | 87 | NA | US | United States | MO | 133 | NA | NA | Missouri | Mississippi County | NA | NA | H | STM | stream | America/Indiana/Knox | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23236 | Bellport (NY) | 5036 | 5108714 | Bellport | 40.75704 | -72.93927 | 8 | 2377 | US | United States | NY | 103 | NA | NA | New York | Suffolk County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 29164 | Sleepy Hollow (NY) | 4340 | 5138371 | Sleepy Hollow | 41.08565 | -73.85847 | 27 | 9286 | US | United States | NY | 119 | NA | NA | New York | Westchester County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 28872 | Sandwich (Mass) | 4736 | 4950191 | Sandwich | 41.75899 | -70.49392 | 4 | 34886 | US | United States | MA | 001 | NA | NA | Massachusetts | Cape Cod | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27500 | New Orleans (La) | 148 | 4335045 | New Orleans | 29.95465 | -90.07507 | NA | 484674 | US | United States | LA | 071 | NA | NA | Louisiana | Orleans Parish | NA | NA | P | PPL | populated place | America/Chicago | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24148 | Clifton (NJ) | 4140 | 5096699 | Clifton | 40.85843 | -74.16375 | 57 | 80245 | US | United States | NJ | 031 | NA | NA | New Jersey | Passaic County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 23036 | Baltimore (Md) | 776 | 4347778 | Baltimore | 39.29039 | -76.61219 | 10 | 610892 | US | United States | MD | 510 | NA | NA | Maryland | City of Baltimore | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27416 | Nebraska | 700 | 5073708 | Nebraska | 41.50028 | -99.75067 | 817 | 1757399 | US | United States | NE | NA | NA | NA | Nebraska | NA | NA | NA | A | ADM1 | first-order administrative division | America/North_Dakota/New_Salem | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 24980 | Fish Creek (Wis) | 6444 | 5253132 | Fish Creek | 45.12777 | -87.24705 | 184 | NA | US | United States | WI | 029 | NA | NA | Wisconsin | Door County | NA | NA | P | PPL | populated place | America/Menominee | -5 | -6 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 70316 | Elmira (NY) | 8556 | 5116497 | Elmira | 42.08980 | -76.80773 | 260 | 29200 | US | United States | NY | 015 | NA | NA | New York | Chemung County | NA | NA | P | PPLA2 | seat of a second-order administrative division | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 70296 | Danbury (Conn) | 8352 | 4832353 | Danbury | 41.39482 | -73.45401 | 121 | 80893 | US | United States | CT | 001 | NA | NA | Connecticut | Fairfield County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 30028 | Vermont | 452 | 5242283 | Vermont | 44.00034 | -72.74983 | 271 | 624501 | US | United States | VT | NA | NA | NA | Vermont | NA | NA | NA | A | ADM1 | first-order administrative division | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 27360 | Napa (Calif) | 1704 | 5376095 | Napa | 38.29714 | -122.28553 | 6 | 77015 | US | United States | CA | 055 | NA | NA | California | Napa County | NA | NA | P | PPL | populated place | America/Los_Angeles | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 30148 | Warwick (NY) | 7516 | 5143285 | Warwick | 41.25648 | -74.35988 | 158 | 6618 | US | United States | NY | 071 | NA | NA | New York | Orange County | NA | NA | P | PPL | populated place | America/New_York | -4 | -5 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
| OK | Copyright (c) 2015 The New York Times Company. All Rights Reserved. | 20 | 68128 | Newport (Ore) | 7900 | 5742750 | Newport | 44.63678 | -124.05345 | 42 | 9515 | US | United States | OR | 041 | NA | NA | Oregon | Lincoln County | NA | NA | P | PPL | populated place | America/Los_Angeles | -7 | -8 | 2013-02-25 15:10:12-05:00 | 2013-02-25 15:10:12-05:00 |
USsites<- USDataFrame[,8:12]
names(USsites) <- c("Name","Latitude","Longitude","Elevation","Population")
USsites <- filter(USsites, Population > 30000 & Elevation > 100)
USsites %>%
kable() %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
scroll_box(width="100%",height="300px")| Name | Latitude | Longitude | Elevation | Population |
|---|---|---|---|---|
| Charlottesville | 38.02931 | -78.47668 | 142 | 34703 |
| Nebraska | 41.50028 | -99.75067 | 817 | 1757399 |
| Danbury | 41.39482 | -73.45401 | 121 | 80893 |
| Vermont | 44.00034 | -72.74983 | 271 | 624501 |
wm<-map_data("world")
usM<-ggplot() + geom_polygon(data = wm, aes(x=long, y = lat, group = group), fill = NA, color = "black") + coord_fixed(1.5)
usM<-usM+xlim(-125,-65)+ylim(22,52)
usM+geom_point(data=USsites,aes(x=Longitude,y=Latitude,color="Places"), size=3)+
labs(color="United States")+theme_bw()[FIT] Fitzgerald, J. Working with The New York Times API in R. Data Journalism in R. Storybench: Tools, Tips and Takeaways on Digital Storytelling from Northeastern University’s School of Journalism. January 25, 2018. Retrieved from Website: http://www.storybench.org/working-with-the-new-york-times-api-in-r/
[GEO] Retrieved from Website: http://developer.nytimes.com/geo_api_v2.json#/README