test1

knitr::opts_chunk$set(echo = TRUE)

orgdat <- read.csv("organdata.csv", header = T)
head(orgdat)
nrow(orgdat)
## [1] 238
ncol(orgdat)
## [1] 21
summary(orgdat)
##    country              year               donors           pop        
##  Length:238         Length:238         Min.   : 5.20   Min.   :  3514  
##  Class :character   Class :character   1st Qu.:13.00   1st Qu.:  6938  
##  Mode  :character   Mode  :character   Median :15.10   Median : 15531  
##                                        Mean   :16.48   Mean   : 39921  
##                                        3rd Qu.:19.60   3rd Qu.: 57301  
##                                        Max.   :33.90   Max.   :288369  
##                                        NA's   :34      NA's   :17      
##     pop_dens            gdp           gdp_lag          health    
##  Min.   : 0.2204   Min.   :12917   Min.   :11434   Min.   : 791  
##  1st Qu.: 1.9377   1st Qu.:19546   1st Qu.:19034   1st Qu.:1581  
##  Median : 9.4908   Median :22756   Median :22158   Median :1956  
##  Mean   :12.0011   Mean   :22986   Mean   :22575   Mean   :2074  
##  3rd Qu.:19.1106   3rd Qu.:26180   3rd Qu.:25887   3rd Qu.:2408  
##  Max.   :38.8851   Max.   :36554   Max.   :36554   Max.   :5665  
##  NA's   :17        NA's   :17                                    
##    health_lag     pubhealth        roads           cerebvas    
##  Min.   : 727   Min.   :4.30   Min.   : 58.21   Min.   :300.0  
##  1st Qu.:1542   1st Qu.:5.50   1st Qu.: 83.46   1st Qu.:500.0  
##  Median :1850   Median :6.00   Median :111.22   Median :604.0  
##  Mean   :1973   Mean   :6.19   Mean   :113.04   Mean   :610.8  
##  3rd Qu.:2290   3rd Qu.:6.90   3rd Qu.:139.57   3rd Qu.:698.0  
##  Max.   :5267   Max.   :8.80   Max.   :232.48   Max.   :957.0  
##                 NA's   :21     NA's   :17       NA's   :17     
##     assault          external        txp_pop          world          
##  Min.   :  4.00   Min.   :258.0   Min.   :0.2204   Length:238        
##  1st Qu.:  9.00   1st Qu.:367.0   1st Qu.:0.6268   Class :character  
##  Median : 11.00   Median :421.0   Median :0.7116   Mode  :character  
##  Mean   : 16.53   Mean   :450.1   Mean   :0.7214                     
##  3rd Qu.: 16.00   3rd Qu.:534.0   3rd Qu.:0.8313                     
##  Max.   :103.00   Max.   :853.0   Max.   :1.1191                     
##  NA's   :17       NA's   :17      NA's   :17                         
##      opt            consent_law        consent_practice    consistent       
##  Length:238         Length:238         Length:238         Length:238        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ccode          
##  Length:238        
##  Class :character  
##  Mode  :character  
##                    
##                    
##                    
## 
str(orgdat)
## 'data.frame':    238 obs. of  21 variables:
##  $ country         : chr  "Australia" "Australia" "Australia" "Australia" ...
##  $ year            : chr  NA "1/1/91" "1/1/92" "1/1/93" ...
##  $ donors          : num  NA 12.1 12.3 12.5 10.2 ...
##  $ pop             : int  17065 17284 17495 17667 17855 18072 18311 18518 18711 18926 ...
##  $ pop_dens        : num  0.22 0.223 0.226 0.228 0.231 ...
##  $ gdp             : int  16774 17171 17914 18883 19849 21079 21923 22961 24148 25445 ...
##  $ gdp_lag         : int  16591 16774 17171 17914 18883 19849 21079 21923 22961 24148 ...
##  $ health          : num  1300 1379 1455 1540 1626 ...
##  $ health_lag      : num  1224 1300 1379 1455 1540 ...
##  $ pubhealth       : num  4.8 5.4 5.4 5.4 5.4 5.5 5.6 5.7 5.9 6.1 ...
##  $ roads           : num  137 122 113 111 108 ...
##  $ cerebvas        : int  682 647 630 611 631 592 576 525 516 493 ...
##  $ assault         : int  21 19 17 18 17 16 17 17 16 15 ...
##  $ external        : int  444 425 406 376 387 371 395 385 410 409 ...
##  $ txp_pop         : num  0.938 0.926 0.915 0.906 0.896 ...
##  $ world           : chr  "Liberal" "Liberal" "Liberal" "Liberal" ...
##  $ opt             : chr  "In" "In" "In" "In" ...
##  $ consent_law     : chr  "Informed" "Informed" "Informed" "Informed" ...
##  $ consent_practice: chr  "Informed" "Informed" "Informed" "Informed" ...
##  $ consistent      : chr  "Yes" "Yes" "Yes" "Yes" ...
##  $ ccode           : chr  "Oz" "Oz" "Oz" "Oz" ...
factor(orgdat$world)
##   [1] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
##   [7] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
##  [13] Liberal     Liberal     Corporatist Corporatist Corporatist Corporatist
##  [19] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [25] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [31] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [37] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [43] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
##  [49] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
##  [55] Liberal     Liberal     SocDem      SocDem      SocDem      SocDem     
##  [61] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
##  [67] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
##  [73] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
##  [79] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
##  [85] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [91] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
##  [97] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [103] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [109] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [115] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [121] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [127] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [133] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [139] Liberal     Liberal     SocDem      SocDem      SocDem      SocDem     
## [145] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
## [151] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
## [157] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
## [163] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
## [169] <NA>        <NA>        <NA>        <NA>        <NA>        <NA>       
## [175] <NA>        <NA>        <NA>        <NA>        <NA>        <NA>       
## [181] <NA>        <NA>        SocDem      SocDem      SocDem      SocDem     
## [187] SocDem      SocDem      SocDem      SocDem      SocDem      SocDem     
## [193] SocDem      SocDem      SocDem      SocDem      Corporatist Corporatist
## [199] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [205] Corporatist Corporatist Corporatist Corporatist Corporatist Corporatist
## [211] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [217] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [223] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [229] Liberal     Liberal     Liberal     Liberal     Liberal     Liberal    
## [235] Liberal     Liberal     Liberal     Liberal    
## Levels: Corporatist Liberal SocDem
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.3.3
orgdat %>% select(1:6) %>% sample_n(size = 10)
p1 <- ggplot(data = orgdat, mapping = aes(x = year, y = donors))
p1 + geom_point()
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_point()`).

p2 <- ggplot(data = orgdat, mapping = aes(x = year, y = donors))
p2 + geom_line(aes(group = country)) + facet_wrap(~country)
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_line()`).

p3 <- ggplot(data = orgdat, mapping = aes(x = country, y = donors))
p3 + geom_boxplot()
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

p4 <- ggplot(data = orgdat,
mapping = aes(x = reorder(country, donors, na.rm=TRUE), y = donors, color = world))
p4 + geom_point() + labs(x=NULL, y = "Donors") + coord_flip() + theme(legend.position = "top")
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_point()`).