setwd("C:/Users/asus4/OneDrive/Desktop/TUGAS/VDE")
dataorg = read.csv("C:/Users/asus4/Downloads/organdata.csv", header=T, sep=",")
head(dataorg)
##     country   year donors   pop  pop_dens   gdp gdp_lag health health_lag
## 1 Australia   <NA>     NA 17065 0.2204433 16774   16591   1300       1224
## 2 Australia 1/1/91  12.09 17284 0.2232723 17171   16774   1379       1300
## 3 Australia 1/1/92  12.35 17495 0.2259980 17914   17171   1455       1379
## 4 Australia 1/1/93  12.51 17667 0.2282198 18883   17914   1540       1455
## 5 Australia 1/1/94  10.25 17855 0.2306484 19849   18883   1626       1540
## 6 Australia 1/1/95  10.18 18072 0.2334516 21079   19849   1737       1626
##   pubhealth    roads cerebvas assault external   txp_pop   world opt
## 1       4.8 136.5954      682      21      444 0.9375916 Liberal  In
## 2       5.4 122.2518      647      19      425 0.9257116 Liberal  In
## 3       5.4 112.8322      630      17      406 0.9145470 Liberal  In
## 4       5.4 110.5451      611      18      376 0.9056433 Liberal  In
## 5       5.4 107.9810      631      17      387 0.8961075 Liberal  In
## 6       5.5 111.6091      592      16      371 0.8853475 Liberal  In
##   consent_law consent_practice consistent ccode
## 1    Informed         Informed        Yes    Oz
## 2    Informed         Informed        Yes    Oz
## 3    Informed         Informed        Yes    Oz
## 4    Informed         Informed        Yes    Oz
## 5    Informed         Informed        Yes    Oz
## 6    Informed         Informed        Yes    Oz
tail(dataorg)
##           country   year donors    pop pop_dens   gdp gdp_lag health health_lag
## 233 United States 1/1/98  21.00 275854 2.864798 31612   30283   4096       3939
## 234 United States 1/1/99  20.87 279040 2.897885 33016   31612   4298       4096
## 235 United States 1/1/00  21.21 282224 2.930952 34590   33016   4538       4298
## 236 United States 1/1/01  21.31 285318 2.963084 35118   34590   4869       4538
## 237 United States 1/1/02  21.47 288369 2.994769 36006   35118   5267       4869
## 238 United States   <NA>     NA     NA       NA    NA   36006   5665       5267
##     pubhealth    roads cerebvas assault external   txp_pop   world opt
## 233       5.8 150.4455      428      68      519 0.9932791 Liberal  In
## 234       5.8 149.5019      440      64      514 0.9819381 Liberal  In
## 235       5.8 148.6231      432      61      499 0.9708600 Liberal  In
## 236       6.2 147.8911      424      58      484 0.9603320 Liberal  In
## 237       6.6 148.4730      416      55      469 0.9501715 Liberal  In
## 238        NA       NA       NA      NA       NA        NA Liberal  In
##     consent_law consent_practice consistent ccode
## 233    Informed         Informed        Yes   USA
## 234    Informed         Informed        Yes   USA
## 235    Informed         Informed        Yes   USA
## 236    Informed         Informed        Yes   USA
## 237    Informed         Informed        Yes   USA
## 238    Informed         Informed        Yes   USA
nrow(dataorg)
## [1] 238
summary(dataorg)
##    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  
##                    
##                    
##                    
## 
unique(dataorg$country)
##  [1] "Australia"      "Austria"        "Belgium"        "Canada"        
##  [5] "Denmark"        "Finland"        "France"         "Germany"       
##  [9] "Italy"          "Ireland"        "Netherlands"    "Norway"        
## [13] "Spain"          "Sweden"         "Switzerland"    "United Kingdom"
## [17] "United States"
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
p1 <- ggplot(data = dataorg, 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 = dataorg, 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 = dataorg, mapping = aes(x = country, y = donors))
p3 + geom_boxplot()
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

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

p3 <- ggplot(data = dataorg, mapping = aes(x = reorder(country, donors, na.rm = TRUE), y = donors))
p3 + geom_boxplot() + coord_flip() + labs(x = NULL, y = "Donors")
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

p3 <- ggplot(data = dataorg, mapping = aes(x = reorder(country, donors, na.rm = TRUE), y = donors, fill=world))
p3 + geom_boxplot() + coord_flip() + labs(x = NULL, y = "Donors") + theme(legend.position = "top")
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

p4 <- ggplot(data = dataorg,
mapping = aes(x = reorder(country, donors, na.rm=TRUE),
y = donors, color = world))
p4 + geom_jitter(position = position_jitter(width=0.15)) + 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()`).