library(ggplot2)
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ✓ purrr   0.3.4
## ── Conflicts ───────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggrepel)
library(data.table)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
## The following object is masked from 'package:purrr':
## 
##     transpose
install.packages("flexdashboard")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
library(flexdashboard)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(DT)

econ_data<-read.csv("EconomistData.csv")
econ_data<-read.csv("EconomistData.csv")

#Pseudocode for creating the chart
#On the x-axis we put CPI
#On the Y-axis we put HDI
#May need to rescale the values on the axis
#Set the color of the dots equal to the region
#Add in the line of best fit smoothed
#Add in the headers and axis labels
#Add in the country labels and use the repel function
#Potentially change the lines on the graph
econ<-ggplot(data = econ_data, mapping = aes(x = CPI,y = HDI)) +
                  geom_point(mapping = aes(color = Region), size = 2 ,fill="white",shape=1) +
  geom_smooth(method = "lm", formula = y ~ log(x), color = "red", se = FALSE,size=0.5)+ labs(x = "Corruption Perceptions Index, 2011 (10=least corrupt)", y ="Human Development Index, 2011 (1=best)",title="Corruption and human development",caption = "Sources: Transparency International; UN Human Development Report")+ scale_x_continuous(limits=c(1,10), n.breaks = 10) + scale_y_continuous(limits=c(0.2,1.0), n.breaks = 9)+theme_bw()+theme(panel.grid.major.x =element_blank(), 
                     panel.grid.minor.x=element_blank())+
  theme(plot.title=element_text(face='bold',size = 14))+
  theme(axis.title.x=element_text(face="italic",size = 7))+
  theme(axis.title.y=element_text(face="italic",size = 7))+
  theme(plot.caption=element_text(size = 7,hjust = 0))+
  theme(legend.position='top')+geom_text_repel(aes(label = Country), color = "black", data = subset(econ_data, Country %in% c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan","Afghanistan", "Congo", "Greece", "Argentina", "Brazil","India", "Italy", "China", "South Africa", "Spane","Botswana", 
"Cape Verde", "Bhutan", "Rwanda", "France","US", "Germany", "Britain", "Barbados", "Norway","Japan", "New Zealand", "Singapore")),check_overlap = TRUE,size=3.0,family="calibri")+scale_color_discrete(labels=c("OECD","Americas",
"Asia & Oceana","Central and Eastern Europe",
"Middle East & north Africa","Sub-Saharan Africa"))+scale_color_manual(values=c("EU W. Europe"="#483D8B","Asia Pacific" = "#00FFFF","East EU Cemt Asia"= "#4682B4","MENA"="#FF0000","SSA"="#8B0000","Americas"="#1E90FF"))+
  geom_text(x=8,y=.3,label="R^2=56%",color="red")
## Warning: Ignoring unknown parameters: check_overlap
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
ggplotly(econ)
## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomTextRepel() has yet to be implemented in plotly.
##   If you'd like to see this geom implemented,
##   Please open an issue with your example code at
##   https://github.com/ropensci/plotly/issues

Data Table

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

Another Graph

econ_data<-econ_data%>%group_by(Region)%>%mutate(avg_hdi_rank=sum(HDI.Rank)/n())

new_graph<-ggplot(data = econ_data,aes(x=Region,y=avg_hdi_rank))+
  geom_bar(stat = "identity",color="blue")+
  theme_minimal()+labs(y="total HDI Rank")
  
ggplotly(new_graph)