Pseudocode

Graphs

Column

Can add text to each and use the HTML tags to center

econ <- import("EconomistData.csv")
econ$Country[166] <- "US"
x.scale <- seq(0,10,by=1)

y.scale <- seq(0.2,1,by=.1)

point.labels <- c("Congo", "Afghanistan","Sudan", "Myanmar", "Iraq", "Venezuela", "Russia", "Argentina", "Greece","Brazil", "Italy", "Spain", "France", "US", "Germany", "Norway", "New Zealand", "Singapore","Japan", "Britain", "Barbados","Botswana", "Cape Verde", "Bhutan", "Rwanda", "South Africa","China", "India")

check.labels <- function(x,y){
  intersection <- intersect(x,y)
  intersection
}

econ$Region <- factor(econ$Region,levels = c("EU W. Europe", "Americas", "Asia Pacific", "East EU Cemt Asia","MENA","SSA"), labels = c("OECD","Americas","Asia &\nOceania","Central &\nEastern Europe","Middle East &\nnorth Africa","Sub-Saharan\nAfrica"))

econ1 <- lm(CPI ~ HDI, data = econ)
r2 <- broom::glance(econ1) %>% pull(r.squared)
r2 <- percent(r2)

econ.plot <- ggplot(data=econ,aes(x=CPI,y=HDI)) +
  
geom_point(aes(color=Region),size=3,shape=21,fill="white") +
scale_color_manual(values=c("OECD"="turquoise4","Americas"="deepskyblue2", "Asia &\nOceania"="lightskyblue1", "Central &\nEastern Europe"="turquoise3", "Middle East &\nnorth Africa"="orangered",
"Sub-Saharan\nAfrica"="orangered4")) +
  
stat_smooth(method="lm", formula=y~log(x), fullrange=T,se=F,color="red") + 
  
labs(x="Corruption Perceptions Index, 2011 (10=least corrupt)", y="Human Development Index, 2011 (1=best)", title="Corruption and human development") +

scale_x_continuous(breaks=x.scale, labels=x.scale,limits=c(1,10)) +

scale_y_continuous(breaks=y.scale,labels=y.scale,limits=c(.2,1)) + 
  
ggrepel::geom_text_repel(aes(label=ifelse(Country %in% point.labels,as.character(Country),'')), size=3) + theme_bw() + 

theme(legend.position = 'top', legend.text = element_text(size = 8),legend.title=element_text(size=0),
panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(), panel.grid.minor.y = element_blank(), panel.grid.major.y = element_line( size=.1, color="black"), axis.ticks.length.x = unit(-0.15, "cm"), axis.ticks.length.y = unit(0, "cm"), 
axis.text.x = element_text(vjust = -3), axis.title.x = element_text(face = "italic", size = 7, vjust = -2), 
axis.title.y = element_text(face = "italic", size = 7), plot.title = element_text(size = 12, face = "bold"), panel.border = element_blank(), axis.line.x = element_line(colour = 'black', size = 0.1), plot.caption = element_text(vjust = -.1, hjust=-.1, size = 7, face = "italic")) +
  

labs(caption = ("Sources: Transparency International; UN Human Development Report")) + 
  
labs(caption = '≠') +

guides(color = guide_legend(nrow = 1)) + 
  
annotate(geom = "text" , x = 9, y = 0.55, label = glue::glue("R^2 = {r}", r=r2), size=4, parse=F)

econ.plot

Column

Data Table

library(DT)
table <- datatable(econ_data, options = list(pageLength = 20))

table 

Average HDI By Region

oecd <- filter(econ,Region=="OECD")
oecd.mean <- mean(oecd$HDI)
americas <- filter(econ,Region=="Americas")
americas.mean <- mean(americas$HDI)
asia <- filter(econ,Region=="Asia &\nOceania")
asia.mean <- mean(asia$HDI)
central.eu <- filter(econ,Region=="Central &\nEastern Europe")
central.eu.mean <- mean(central.eu$HDI)
mena <- filter(econ,Region=="Middle East &\nnorth Africa")
mena.mean <- mean(mena$HDI)
africa <- filter(econ,Region=="Sub-Saharan\nAfrica")
africa.mean <- mean(africa$HDI)

means <- c(oecd.mean,americas.mean,asia.mean,central.eu.mean,mena.mean,africa.mean)
countries <- c("OECD","Americas","Asia &\nOceania",
               "Central &\nEastern Europe",
               "Middle East &\nnorth Africa","Sub-Saharan\nAfrica")
bar.graph.data <- data.frame(countries,means)
bar.graph <- ggplot(data=bar.graph.data,aes(x=countries,y=means)) + 
  geom_bar(stat="identity",color="navy",fill="navy") + xlab("Regions of the World")+
  ylab("Mean Human Development Index Score") + labs(title="Mean HDI Score By Region")

ggplotly(bar.graph)