title: “assignment1” author: “Keith DeNivo” date: “2024-02-03” output: pdf_document: default html_document: default

Overview. What the world thinks of Trump. The article chosen link https://fivethirtyeight.com/features/what-the-world-thinks-of-trump/. The article includes countries approval ratings of Donald Trump and the U.S.A. in general. Specifically the topic from the article that will be analyzed is “Have a favorable view of the U.S.?” The poll was conducted by Pew Research Center which surveyed ~1000 people from every country. the average approval was extracted and analyzed. Comments are provided after the r code blocks.

library(devtools)
## Loading required package: usethis
library(RCurl)
library(plyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.4.4     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::arrange()   masks plyr::arrange()
## ✖ purrr::compact()   masks plyr::compact()
## ✖ tidyr::complete()  masks RCurl::complete()
## ✖ dplyr::count()     masks plyr::count()
## ✖ dplyr::desc()      masks plyr::desc()
## ✖ dplyr::failwith()  masks plyr::failwith()
## ✖ dplyr::filter()    masks stats::filter()
## ✖ dplyr::id()        masks plyr::id()
## ✖ dplyr::lag()       masks stats::lag()
## ✖ dplyr::mutate()    masks plyr::mutate()
## ✖ dplyr::rename()    masks plyr::rename()
## ✖ dplyr::summarise() masks plyr::summarise()
## ✖ dplyr::summarize() masks plyr::summarize()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(DescTools)
library(ggpubr)
## 
## Attaching package: 'ggpubr'
## 
## The following object is masked from 'package:plyr':
## 
##     mutate
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
## 
## Attaching package: 'openintro'
## 
## The following object is masked from 'package:DescTools':
## 
##     cards
library (readr)




c <- getURL("https://raw.githubusercontent.com/fivethirtyeight/data/master/trump-world-trust/TRUMPWORLD-us.csv")
world_us_approve <- data.frame(read.csv(text = c ))

Data Scraping. Data was downloaded and put into a data frame world_us_approve

glimpse(world_us_approve)
## Rows: 17
## Columns: 39
## $ year         <int> 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 201…
## $ avg          <dbl> 67.50000, 61.50000, 44.69231, 35.66667, 43.58333, 35.3333…
## $ Canada       <int> NA, 72, 63, NA, 59, NA, 55, NA, 68, NA, NA, NA, 64, NA, 6…
## $ France       <int> 62, 62, 42, 37, 43, 39, 39, 42, 75, 73, 75, 69, 64, 75, 7…
## $ Germany      <int> 78, 60, 45, 38, 42, 37, 30, 31, 64, 63, 62, 52, 53, 51, 5…
## $ Greece       <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 35, 39, 34, N…
## $ Hungary      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ Italy        <int> 76, 70, 60, NA, NA, NA, 53, NA, NA, NA, NA, 74, 76, 78, 8…
## $ Netherlands  <int> NA, NA, NA, NA, 45, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ Poland       <int> 86, 79, NA, NA, 62, NA, 61, 68, 67, 74, 70, 69, 67, 73, 7…
## $ Spain        <int> 50, NA, 38, NA, 41, 23, 34, 33, 58, 61, 64, 58, 62, 60, 6…
## $ Sweden       <int> NA, NA, NA, NA, NA, NA, 46, NA, NA, NA, NA, NA, NA, NA, N…
## $ UK           <int> 83, 75, 70, 58, 55, 56, 51, 53, 69, 65, 61, 60, 58, 66, 6…
## $ Russia       <int> 37, 61, 37, 46, 52, 43, 41, 46, 44, 57, 56, 52, 51, 23, 1…
## $ Australia    <int> NA, NA, 59, NA, NA, NA, NA, 46, NA, NA, NA, NA, 66, NA, 6…
## $ India        <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 56, 55, 7…
## $ Indonesia    <int> NA, NA, NA, NA, 38, 30, 29, 37, 63, 59, 54, NA, 61, 59, 6…
## $ Japan        <int> 77, 72, NA, NA, NA, 63, 61, 50, 59, 66, 85, 72, 69, 66, 6…
## $ Philippines  <int> NA, 90, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 85, 92, 9…
## $ South.Korea  <int> 58, 52, 46, NA, NA, NA, 58, 70, 78, 79, NA, NA, 78, 82, 8…
## $ Vietnam      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 76, 7…
## $ Israel       <int> NA, NA, 78, NA, NA, NA, 78, NA, 71, NA, 72, NA, 83, 84, 8…
## $ Jordan       <int> NA, 25, 1, 5, 21, 15, 20, 19, 25, 21, 13, 12, 14, 12, 14,…
## $ Lebanon      <int> NA, 36, 27, NA, 42, NA, 47, 51, 55, 52, 49, 48, 47, 41, 3…
## $ Tunisia      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 45, 42, 42, N…
## $ Turkey       <int> 52, 30, 15, 30, 23, 12, 9, 12, 14, 17, 10, 15, 21, 19, 29…
## $ Ghana        <int> NA, 83, NA, NA, NA, NA, 80, NA, NA, NA, NA, NA, 83, 77, 8…
## $ Kenya        <int> 94, 80, NA, NA, NA, NA, 87, NA, 90, 94, 83, NA, 81, 80, 8…
## $ Nigeria      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, 81, NA, NA, 69, 69, 7…
## $ Senegal      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 81, 74, 8…
## $ South.Africa <int> NA, 65, NA, NA, NA, NA, NA, 60, NA, NA, NA, NA, 72, 68, 7…
## $ Tanzania     <int> NA, 53, NA, NA, NA, NA, 46, 65, NA, NA, NA, NA, NA, 75, 7…
## $ Argentina    <int> 50, 34, NA, NA, NA, NA, 16, 22, 38, 42, NA, NA, 41, 36, 4…
## $ Brazil       <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, 62, 62, 61, 73, 65, 7…
## $ Chile        <int> NA, NA, NA, NA, NA, NA, 55, NA, NA, NA, NA, NA, 68, 72, 6…
## $ Colombia     <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 64, N…
## $ Mexico       <int> 68, 64, NA, NA, NA, NA, 56, 47, 69, 56, 52, 56, 66, 63, 6…
## $ Peru         <int> 74, 67, NA, NA, NA, NA, 61, NA, NA, NA, NA, NA, NA, 65, 7…
## $ Venezuela    <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 53, 62, 5…
names(world_us_approve)
##  [1] "year"         "avg"          "Canada"       "France"       "Germany"     
##  [6] "Greece"       "Hungary"      "Italy"        "Netherlands"  "Poland"      
## [11] "Spain"        "Sweden"       "UK"           "Russia"       "Australia"   
## [16] "India"        "Indonesia"    "Japan"        "Philippines"  "South.Korea" 
## [21] "Vietnam"      "Israel"       "Jordan"       "Lebanon"      "Tunisia"     
## [26] "Turkey"       "Ghana"        "Kenya"        "Nigeria"      "Senegal"     
## [31] "South.Africa" "Tanzania"     "Argentina"    "Brazil"       "Chile"       
## [36] "Colombia"     "Mexico"       "Peru"         "Venezuela"

Data Information. General info about the data

countries <- world_us_approve[0,3:39]
 countries
##  [1] Canada       France       Germany      Greece       Hungary     
##  [6] Italy        Netherlands  Poland       Spain        Sweden      
## [11] UK           Russia       Australia    India        Indonesia   
## [16] Japan        Philippines  South.Korea  Vietnam      Israel      
## [21] Jordan       Lebanon      Tunisia      Turkey       Ghana       
## [26] Kenya        Nigeria      Senegal      South.Africa Tanzania    
## [31] Argentina    Brazil       Chile        Colombia     Mexico      
## [36] Peru         Venezuela   
## <0 rows> (or 0-length row.names)

Countries Surveyed. Above is a list of the countries surveyed

average_world_us_approve <- data.frame(year = world_us_approve$year, average_world_approval = world_us_approve$avg) 

Data Frame with Subset. a new data frame average_world_us_approve was created that only had the years and the average country approval rating of the US. the avg column was renamed average_world_approval.

average_world_us_approve_plot <- ggplot( average_world_us_approve, aes(x = year, y = average_world_approval)) + 
   geom_point() 
   average_world_us_approve_plot +
stat_smooth(method = "loess",
formula = y ~ x ,
geom = "smooth" )

Graph 1. Graph of the years vs the average approval ratings with a basic trendline.

 min(average_world_us_approve$year)
## [1] 2000
 max(average_world_us_approve$year)
## [1] 2017
 range(average_world_us_approve$average_world_approval)
## [1] 35.33333 67.50000
 mean(average_world_us_approve$average_world_approval)
## [1] 53.52606
sd(average_world_us_approve$average_world_approval)
## [1] 10.16204

Findings and Recommendations. The world approval of the U.S.A. averages at 53.5% from 2000 to 2017. the world approval of the US decreased from 2000 to 2005 which coincides with the Bush era and then the approval rating increased with the Obama presidency. Then approvals decreased again with the presidency of Trump, however it did not decrease to levels below the Bush presidency. In order to verify the work, more information from more sources would need to be gathered such as additional polls from other institutions. One way to add information would be to see which countries like the US more than average would be to take the ratio of each countries approval rating and divide it by the average. This ratio would tell you which country favors the US more than the average or not. A graph of this ratio over time would show if the country consistently favors the US more than the average or if they do not.