Stat. 651: ggplot2

Author

Prof. Eric A. Suess

ggplot2 examples

library(tidyverse)
library(mdsr)
library(mosaicData)

CIACounties

Make the base plot g and then add different layers on to it.

head(CIACountries)
         country      pop    area oil_prod   gdp educ   roadways net_users
1    Afghanistan 32564342  652230        0  1900   NA 0.06462444       >5%
2        Albania  3029278   28748    20510 11900  3.3 0.62613051      >35%
3        Algeria 39542166 2381741  1420000 14500  4.3 0.04771929      >15%
4 American Samoa    54343     199        0 13000   NA 1.21105528      <NA>
5        Andorra    85580     468       NA 37200   NA 0.68376068      >60%
6         Angola 19625353 1246700  1742000  7300  3.5 0.04125211      >15%
# base plot g

g <- CIACountries |>  ggplot(aes(y = gdp, x = educ)) 

g + geom_point()
Warning: Removed 64 rows containing missing values (`geom_point()`).

g + geom_point(size = 3)
Warning: Removed 64 rows containing missing values (`geom_point()`).

g + geom_point(aes(color = net_users), size = 3)
Warning: Removed 64 rows containing missing values (`geom_point()`).