Matthew Kusen

Problem 1

Create the following figure, using the data included in the R Markdown file.

####HINT: Use the following code to get the colors right
#scale_fill_distiller(palette=5)
####HINT: make sure you use left_join to combine the data_values above to the world map data in my_world_map
####PUT YOUR CODE HERE

map <- left_join(my_world_map,some_data_values,by="region")
ggplot(data = map, mapping = aes(x= long, y= lat,
                                 group=group, 
                                 fill=Score))+
  geom_polygon()+
  labs(title="Problem 1")+
  scale_fill_distiller(palette = "Greens")

Problem 2

Create the following figure, using the data included in the R Markdown file.

####Make sure you load any necessary libraries
####HINT: Use a filter command to get just maps of Costa Rica, Panama, and Nicaragua
####Hint: Use a filter command to put in points only for cities with a population of greater than 40,000. This should leave you with 32 cities.
####Hint: Use add_column to attach the "Measurement" variable to your data, and set that to the color aesthetic when you draw the points.
####Hint: set the colors for the city points with scale_color_distiller(palette=7)
####Hint: set the size of all points to the value 5
world <- map_data("world")
CentralAmerica1 <- filter(world,region=="Costa Rica"|
                            region=="Nicaragua"|
                            region=="Panama")
my_cities <-maps::world.cities
CA_big_cities <- filter(my_cities,country.etc=="Costa Rica"|
                            country.etc=="Nicaragua"|
                            country.etc=="Panama",pop>40000)
add_column(CA_big_cities,Measurement)
##              name country.etc    pop   lat   long capital Measurement
## 1        Alajuela  Costa Rica  48366 10.02 -84.23       0    50.25882
## 2        Arraijan      Panama  81118  8.95 -79.65       0    51.83112
## 3      Bluefields   Nicaragua  45703 12.01 -83.77       0    49.66038
## 4      Chinandega   Nicaragua 129730 12.63 -87.13       0    50.89720
## 5          Chitre      Panama  44735  7.97 -80.42       0    50.48802
## 6  Ciudad Sandino   Nicaragua  72109 12.16 -86.34       0    48.74461
## 7           Colon      Panama  77983  9.36 -79.90       0    50.02279
## 8           David      Panama  84013  8.44 -82.43       0    51.09077
## 9        El Viejo   Nicaragua  55268 12.67 -87.18       0    49.86788
## 10         Esteli   Nicaragua  99479 13.09 -86.36       0    48.92500
## 11        Granada   Nicaragua  90868 11.94 -85.96       0    50.85501
## 12       Jinotega   Nicaragua  53055 13.10 -86.00       0    49.63502
## 13       Juigalpa   Nicaragua  56712 12.11 -85.38       0    50.16555
## 14    La Chorrera      Panama  62359  8.88 -79.78       0    48.75722
## 15    Las Cumbres      Panama  73219  9.08 -79.53       0    51.45929
## 16           Leon   Nicaragua 146685 12.43 -86.89       0    49.99639
## 17        Liberia  Costa Rica  47906 10.64 -85.45       0    49.97912
## 18          Limon  Costa Rica  64285  9.99 -83.04       0    50.03211
## 19        Managua   Nicaragua 990417 12.15 -86.27       1    48.83272
## 20         Masaya   Nicaragua 134516 11.98 -86.10       0    49.48043
## 21      Matagalpa   Nicaragua 114628 12.93 -85.93       0    51.37389
## 22   Nueva Guinea   Nicaragua  55339 11.69 -84.46       0    51.41233
## 23         Pacora      Panama  56414  9.08 -79.28       0    49.59783
## 24         Panama      Panama 406070  8.97 -79.53       1    49.56086
## 25        Paraiso  Costa Rica  41936  9.83 -83.87       0    51.01061
## 26  San Francisco  Costa Rica  59484  9.99 -84.13       0    50.43082
## 27       San Jose  Costa Rica 339588  9.93 -84.08       1    50.73393
## 28  San Miguelito      Panama 326951  9.03 -79.50       0    49.31933
## 29       Santiago      Panama  46284  8.10 -80.97       0    50.32620
## 30       Tipitapa   Nicaragua 132672 12.20 -86.10       0    50.90703
## 31        Tocumen      Panama  89951  9.08 -79.38       0    49.53732
## 32   Vista Alegre      Panama  42451  8.93 -79.70       0    50.00470
ggplot(data = CentralAmerica1, mapping = aes(x= long,
                                             y= lat,group =group))+
  geom_polygon(color="black",fill="white")+
  geom_point(data = CA_big_cities,aes(x=long,y=lat,
                                      group=NULL,
                                      color=Measurement),
             size=5, alpha=.8)+
  scale_size_continuous() +
  scale_color_distiller(palette=3) +
  theme_classic() +
   theme(axis.text.x = element_blank(),axis.text.y=element_blank(),
        axis.line = element_blank(),axis.ticks = element_blank())+
  labs(x="",y="", title="Panama, Nicaragua, & Costa Rica major cities", 
  caption ="Population > 40,000")

Problem 3

Create the following figure, using the data included in the R Markdown file.

Note that the code in the .rmd file will import a set of simple features data for South America. Make sure you install any necessary packages.

####Make sure you load any necessary libraries
####HINT: the s_america object created in the chunk above is a simple features object with many columns. Identify the correct column based on the solution figure and use it to color in the choropleth.
####HINT: Use scale_fill_distiller and palette 10 to the match the colors.
####PUT YOUR CODE HERE
library(ggrepel)
ggplot()+geom_sf(data= s_america,aes(fill=pop_est))+
  scale_fill_distiller(palette = 10)

Data Wrangling

Simplify GDP data

#Additional Examples

#Asia countries by GDP

Asia <-ne_countries(scale="medium",continent='asia',returnclass="sf")
ggplot()+geom_sf(data= Asia,aes(fill=economy))+
  scale_fill_brewer(palette="Set2")+
  theme_classic()+
  labs(x="",y="",title="Asia Countries by Economy")+
  theme(axis.text.x = element_blank(),axis.text.y=element_blank(),
        axis.line = element_blank(),axis.ticks = element_blank())

ESEAP <-Asia %>% filter(region_wb=="South Asia"|
                          region_wb=="East Asia & Pacific")
table(Asia$region_wb)
## 
##        East Asia & Pacific      Europe & Central Asia 
##                         20                         11 
## Middle East & North Africa                 South Asia 
##                         14                          8
SPRINT <- tibble("admin"=c("Myanmar","Pakistan","Afghanistan","Vietnam","Sri Lanka","Nepal","Indonesia","Philippines"),"SPRINT"=rep("SPRINT"))
ESEAP <- left_join(ESEAP,SPRINT,by="admin")

seAsia <- c("Myanmar","Thailand","Cambodia","Vietnam","Laos","Malaysia","Indonesia","Philippines")
SEA <- Asia %>% filter(name %in% seAsia)


ggplot()+geom_sf(data= ESEAP,aes(fill=SPRINT))+
  scale_fill_brewer()+
  theme_classic()+
  labs(x="",y="",title="SPRINT Countries")+
  theme(axis.text.x = element_blank(),axis.text.y=element_blank(),
        axis.line = element_blank(),axis.ticks = element_blank())+
  scale_fill_manual(values="deepskyblue")
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.

ggplot()+geom_sf(data= SEA,aes(fill=economy))+
  theme_classic()+
  labs(x="",y="",title="SEA countries by Economy")+
  theme(axis.text.x = element_blank(),axis.text.y=element_blank(),
        axis.line = element_blank(),axis.ticks = element_blank())+
  scale_fill_brewer(palette=4)