Skip to content

Instantly share code, notes, and snippets.

@ajdamico
Last active April 21, 2018 13:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
x <-
structure(list(name = c("George Washington", "John Adams", "Thomas Jefferson",
"James Madison", "James Monroe", "John Quincy Adams", "Andrew Jackson",
"Martin Van Buren", "William Henry Harrison", "John Tyler", "James K. Polk",
"Zachary Taylor", "Millard Fillmore", "Franklin Pierce", "James Buchanan",
"Abraham Lincoln", "Andrew Johnson", "Ulysses S. Grant", "Rutherford B. Hayes",
"James A. Garfield", "Chester Arthur", "Grover Cleveland", "Benjamin Harrison",
"William McKinley", "Theodore Roosevelt", "William Howard Taft",
"Woodrow Wilson", "Warren G. Harding", "Calvin Coolidge", "Herbert Hoover",
"Franklin Roosevelt", "Harry S. Truman", "Dwight Eisenhower",
"John F. Kennedy", "Lyndon B. Johnson", "Richard Nixon", "Gerald Ford",
"Jimmy Carter", "Ronald Reagan", "George Bush", "Bill Clinton",
"George W. Bush", "Barack Obama", "Donald Trump"), birth = structure(c(-86876,
-85530, -82808, -79914, -77314, -73953, -74071, -68327, -71913,
-65656, -63612, -67607, -62085, -60304, -65266, -58762, -58807,
-53940, -53780, -50447, -51222, -48501, -49807, -46358, -40608,
-41015, -41276, -38045, -35609, -34842, -32112, -31283, -28933,
-19210, -22407, -20811, -20625, -16528, -21514, -16639, -8536,
-8580, -3072, -8602), class = "Date"), death = structure(c(-62109,
-52411, -52411, -48764, -50585, -44507, -45497, -39242, -47023,
-39429, -44029, -43640, -34997, -36609, -37103, -38246, -34487,
-30842, -28107, -32245, -30359, -22471, -25131, -24946, -18623,
-14544, -16769, -16954, -13510, -1899, -9030, 1090, -279, -2232,
1117, 8877, 13508, NA, 12574, NA, NA, NA, NA,
NA), class = "Date"), term_start = structure(c(-65989, -63124,
-61664, -58742, -55820, -52898, -51437, -48515, -47054, -47023,
-45593, -44132, -43640, -42671, -41210, -39749, -38246, -36827,
-33905, -32444, -32245, -30983, -29522, -26600, -24946, -22218,
-20757, -17835, -16954, -14913, -13452, -9030, -6190, -3268,
-2232, -346, 1681, 2576, 4037, 6959, 8420, 11342, 14264, 17186
), class = "Date"), term_end = structure(c(-63124, -61664, -58742,
-55820, -52898, -51437, -48515, -47054, -47023, -45593, -44132,
-43640, -42671, -41210, -39749, -38246, -36827, -33905, -32444,
-32245, -30983, -29522, -28061, -24946, -22218, -20757, -17835,
-16954, -14913, -13452, -9030, -6190, -3268, -2232, -346, 1681,
2576, 4037, 6959, 8420, 11342, 14264, 17186, NA), class = "Date")), .Names = c("name",
"birth", "death", "term_start", "term_end"), row.names = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 25L, 26L, 27L, 28L, 29L,
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L,
43L, 44L, 45L), class = "data.frame")
first_term_start <- min( x$term_start )
today <- Sys.Date()
x[ is.na( x ) ] <- today + 1
y <-
data.frame(
this_day = seq( first_term_start , today , "day" ) ,
presidents_died =
sapply( seq( first_term_start , today , "day" ) , function( w ) sum( w >= x$death ) ) ,
presidents_started =
sapply( seq( first_term_start , today , "day" ) , function( w ) sum( w >= x$term_start ) )
)
y$living_former_presidents <- y$presidents_started - y$presidents_died - 1
plot( y$this_day , y$living_former_presidents , xlab = '' , ylab = '' , main = 'living former presidents throughout us history' , type = 'l' , bty = 'n' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment