getAmountForYearAreaPair(df3, 2022, "Longtermism") amounts <- c() for(i in c(1:dim(df4)[1])){ amount <- getAmountForYearAreaPair(df3, df4$year[i], df4$area[i]) amounts <- c(amounts, amount) } df4$amount <- amounts df4$cummulative_amount_for_its_area = sapply(df4$area, function(area) { return(getAmountForArea(df3, area)) }) ## Plotting longtermist funding title_text="Open Philanthropy allocation by year and cause area" subtitle_text="restricted to longtermism & GCRs" palette = "Classic Red-Blue" direction = -1 open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt df3 <- list() df3$year <- as.vector(sapply(data$Date, getYear)) df3$amount <- as.vector(sapply(data$Amount, parse_number)) df3$amount <- ifelse(is.na(df$amount), 0, df$amount) df3$area <- as.vector(data$Focus.Area) df3 <- as.data.frame(df3) df3$area <- as.vector(data$Focus.Area) ## Including Dustin Moskovitz's wealth coeff <- 10^7*4 wealth <- c(6, 8, 12, 15, 18, 12, 14, 19, 14) df2$wealth <- rep(wealth * coeff, num_areas) make_fortune_plot <- function(show_fortune_legend = FALSE) { open_philanthropy_plot_with_fortune <- ggplot(data=df2, aes(x=year, y=amount, fill=area, group = cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ geom_point( aes(x=year, y=wealth), size=2, color="darkblue", shape=4, show.legend=show_fortune_legend )+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous( labels = scales::dollar_format(scale = 0.000001, suffix = "M"), name="OpenPhil donations", breaks = c(0:5)*10^8, sec.axis = sec_axis( ~.*1, name="Dustin Moskovitz's fortune\n(est. Bloomberg)", breaks = seq(0,20,by=5)*coeff, labels = c("$0B", "$5B","$10B","$15B", "$20B") ), limits=c(0,8*10^8) )+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), axis.title.y = element_text(vjust=3, hjust=0.25, size=10), axis.title.y.right = element_text(vjust=3, hjust=0.5, size=10), legend.text=element_text(size=8) ) + guides(fill=guide_legend(nrow=4,byrow=TRUE)) # open_philanthropy_plot_with_fortune height = 6 width = 5 filename = ifelse( show_fortune_legend, "open_philanthropy_plot_with_fortune.png", "open_philanthropy_plot_with_fortune_clean_labels.png" ) ggsave(plot=open_philanthropy_plot_with_fortune, filename, width=width, height=height, bg = "white") } make_fortune_plot(TRUE) make_fortune_plot(FALSE) ## Look at the different longtermist areas independently. longtermism <- c("Biosecurity & Pandemic Preparedness", "Potential Risks from Advanced AI", "Science Supporting Biosecurity and Pandemic Preparedness", "Longtermism") df3 <- list() df3$year <- as.vector(sapply(data$Date, getYear)) df3$amount <- as.vector(sapply(data$Amount, parse_number)) df3$amount <- ifelse(is.na(df$amount), 0, df$amount) df3$area <- as.vector(data$Focus.Area) df3 <- as.data.frame(df3) df3$area <- as.vector(data$Focus.Area) df3 <- df3 %>% dplyr::filter(area %in% longtermism) df$area <- ifelse(df3$area %in% ea_growth, "EA Community Building", df$area) ## Group area df3 df3$area <- ifelse(df$area %in% pure_longtermism, "Longtermism", df$area) pure_longtermism = c("Longtermism") biorisk = c("Biosecurity & Pandemic Preparedness", "Science Supporting Biosecurity and Pandemic Preparedness") ai_risk = c( "Potential Risks from Advanced AI") df3$area <- ifelse(df$area %in% pure_longtermism, "Longtermism", df$area) df3$area <- ifelse(df$area %in% biorisk, "Biosecurity & Pandemic Preparedness", df$area) df3$area <- ifelse(df$area %in% ai_risk, "Potential Risks from Advanced AI", df$area) df3 <- list() df3$year <- as.vector(sapply(data$Date, getYear)) df3$amount <- as.vector(sapply(data$Amount, parse_number)) df3$amount <- ifelse(is.na(df$amount), 0, df$amount) df3$area <- as.vector(data$Focus.Area) df3 <- as.data.frame(df3) df3$area <- as.vector(data$Focus.Area) df3 <- df3 %>% dplyr::filter(area %in% longtermism) pure_longtermism = c("Longtermism") biorisk = c("Biosecurity & Pandemic Preparedness", "Science Supporting Biosecurity and Pandemic Preparedness") ai_risk = c( "Potential Risks from Advanced AI") df3$area <- ifelse(df$area %in% pure_longtermism, "Longtermism", df$area) df3$area <- ifelse(df$area %in% biorisk, "Biosecurity & Pandemic Preparedness", df$area) df3 <- list() df3$year <- as.vector(sapply(data$Date, getYear)) df3$amount <- as.vector(sapply(data$Amount, parse_number)) df3$amount <- ifelse(is.na(df$amount), 0, df$amount) df3$area <- as.vector(data$Focus.Area) df3 <- as.data.frame(df3) df3$area <- as.vector(data$Focus.Area) df3 <- df3 %>% dplyr::filter(area %in% longtermism) pure_longtermism = c("Longtermism") biorisk = c("Biosecurity & Pandemic Preparedness", "Science Supporting Biosecurity and Pandemic Preparedness") ai_risk = c( "Potential Risks from Advanced AI") df3$area <- ifelse(df3$area %in% pure_longtermism, "Longtermism", df3$area) df3$area <- ifelse(df3$area %in% biorisk, "Biosecurity & Pandemic Preparedness", df3$area) df3$area <- ifelse(df3$area %in% ai_risk, "Potential Risks from Advanced AI", df3$area) years <- c(2014: 2022) # as.vector(unique(df$year)) num_years <- length(years) area_names <- longtermism num_areas <- length(area_names) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4$year <- rep(years, num_areas) df4 <- as.data.frame(df4) # View(df4) getAmountForYearAreaPair(df3, 2022, "Longtermism") amounts <- c() for(i in c(1:dim(df4)[1])){ amount <- getAmountForYearAreaPair(df3, df4$year[i], df4$area[i]) amounts <- c(amounts, amount) } df4$amount <- amounts df4$cummulative_amount_for_its_area = sapply(df4$area, function(area) { return(getAmountForArea(df3, area)) }) ## Plotting longtermist funding title_text="Open Philanthropy allocation by year and cause area" subtitle_text="restricted to longtermism & GCRs" palette = "Classic Red-Blue" direction = -1 open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt longtermism_labels = c(pure_longtermism, biorisk, ai_risk) open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) years <- c(2014: 2022) # as.vector(unique(df$year)) num_years <- length(years) area_names <- longtermism_labels num_areas <- length(area_names) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4$year <- rep(years, num_areas) df4 <- as.data.frame(df4) # View(df4) getAmountForYearAreaPair(df3, 2022, "Longtermism") amounts <- c() for(i in c(1:dim(df4)[1])){ amount <- getAmountForYearAreaPair(df3, df4$year[i], df4$area[i]) amounts <- c(amounts, amount) } df4$amount <- amounts df4$cummulative_amount_for_its_area = sapply(df4$area, function(area) { return(getAmountForArea(df3, area)) }) ## Plotting longtermist funding title_text="Open Philanthropy allocation by year and cause area" subtitle_text="restricted to longtermism & GCRs" palette = "Classic Red-Blue" direction = -1 open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt ## Look at the different longtermist areas independently. longtermism <- c("Biosecurity & Pandemic Preparedness", "Potential Risks from Advanced AI", "Science Supporting Biosecurity and Pandemic Preparedness", "Longtermism") df3 <- list() df3$year <- as.vector(sapply(data$Date, getYear)) df3$amount <- as.vector(sapply(data$Amount, parse_number)) df3$amount <- ifelse(is.na(df$amount), 0, df$amount) df3$area <- as.vector(data$Focus.Area) df3 <- as.data.frame(df3) df3$area <- as.vector(data$Focus.Area) df3 <- df3 %>% dplyr::filter(area %in% longtermism) pure_longtermism = c("Longtermism") biorisk = c("Biosecurity & Pandemic Preparedness", "Science Supporting Biosecurity and Pandemic Preparedness") ai_risk = c( "Potential Risks from Advanced AI") longtermism_labels = c(pure_longtermism, biorisk, ai_risk) df3$area <- ifelse(df3$area %in% pure_longtermism, "Longtermism", df3$area) df3$area <- ifelse(df3$area %in% biorisk, "Biosecurity & Pandemic Preparedness", df3$area) df3$area <- ifelse(df3$area %in% ai_risk, "Potential Risks from Advanced AI", df3$area) years <- c(2014: 2022) # as.vector(unique(df$year)) num_years <- length(years) area_names <- longtermism_labels num_areas <- length(area_names) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4$year <- rep(years, num_areas) df4 <- as.data.frame(df4) # View(df4) getAmountForYearAreaPair(df3, 2022, "Longtermism") amounts <- c() for(i in c(1:dim(df4)[1])){ amount <- getAmountForYearAreaPair(df3, df4$year[i], df4$area[i]) amounts <- c(amounts, amount) } df4$amount <- amounts df4$cummulative_amount_for_its_area = sapply(df4$area, function(area) { return(getAmountForArea(df3, area)) }) ## Plotting longtermist funding title_text="Open Philanthropy allocation by year and cause area" subtitle_text="restricted to longtermism & GCRs" palette = "Classic Red-Blue" direction = -1 open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt View(df4) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4$area longtermism_labels longtermism_labels = c(pure_longtermism, "Biosecurity & Pandemic Preparedness", ai_risk) df3$area <- ifelse(df3$area %in% pure_longtermism, "Longtermism", df3$area) df3$area <- ifelse(df3$area %in% biorisk, "Biosecurity & Pandemic Preparedness", df3$area) df3$area <- ifelse(df3$area %in% ai_risk, "Potential Risks from Advanced AI", df3$area) years <- c(2014: 2022) # as.vector(unique(df$year)) num_years <- length(years) area_names <- longtermism_labels num_areas <- length(area_names) df4 <- list() df4$area <- sort(rep(area_names, num_years)) df4$year <- rep(years, num_areas) df4 <- as.data.frame(df4) # View(df4) getAmountForYearAreaPair(df3, 2022, "Longtermism") amounts <- c() for(i in c(1:dim(df4)[1])){ amount <- getAmountForYearAreaPair(df3, df4$year[i], df4$area[i]) amounts <- c(amounts, amount) } df4$amount <- amounts df4$cummulative_amount_for_its_area = sapply(df4$area, function(area) { return(getAmountForArea(df3, area)) }) View(df4) ## Plotting longtermist funding title_text="Open Philanthropy allocation by year and cause area" subtitle_text="restricted to longtermism & GCRs" palette = "Classic Red-Blue" direction = -1 open_philanthropy_plot_lt <- ggplot(data=df4, aes(x=year, y=amount, fill=area, group=cummulative_amount_for_its_area))+ geom_bar(stat="identity")+ labs( title=title_text, subtitle=subtitle_text, x=element_blank(), y=element_blank() ) + # scale_fill_wsj() + # scale_fill_tableau(dir =1) + # scale_fill_tableau(palette, dir=direction) + # scale_fill_viridis(discrete = TRUE) + # scale_fill_brewer(palette = "Set2") + scale_fill_d3( "category20", alpha=0.8) + # scale_fill_uchicago("dark") + # scale_fill_startrek() + scale_y_continuous(labels = scales::dollar_format(scale = 0.000001, suffix = "M"))+ scale_x_continuous(breaks = years)+ theme_tufte() + theme( legend.title = element_blank(), legend.text.align = 0, plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5), legend.position="bottom", legend.box="vertical", axis.text.x=element_text(angle=60, hjust=1), legend.text=element_text(size=7) ) + geom_text(aes(label=ifelse(amount > 5e6, paste0(round(amount / 1e6, 0), "M"), "")), size = 2, colour="#f9f9f9", position = position_stack(vjust = 0.5)) + geom_text( aes(label = paste0(round(after_stat(y) / 1e6, 0), "M"), group = year), stat = 'summary', fun = sum, size=2.3, vjust = -0.5 ) + guides(fill=guide_legend(nrow=3,byrow=TRUE)) open_philanthropy_plot_lt getwd() ## Working directory on which the file will be saved. Can be changed with setwd("/your/directory") height = 5 width = 6 ## open_philanthropy_plot_lt ggsave(plot=open_philanthropy_plot_lt, "open_philanthropy_grants_lt_labeled.png", width=width, height=height, bg = "white")