Date Created: 10/5/2018

Introduction

  • This is an R Markdown presentation.
  • This is for Developing Data Products Course Week 3 Assignment in the Data Sciecne Specialization by the John Hopkins University
  • This creates a web page presentation using R Markdown that features a plot created with Plotly.
  • The web page is hosted on RPubs

The Code

The code for the first plot

dat <- read.csv("state_facts.csv")
dat$State <- as.character(dat$State)
x <- list(
  title = "State")
y <- list(
  title = "Poverty Levels (%)")
plot_ly(dat, x=dat$State, y=dat$PovertyLevelPerc, 
        color = dat$Winnner, colors = c("Blue","Red")) %>%
  layout(xaxis=x, yaxis=y, title="Poverty levels accross the US States")
## No trace type specified:
##   Based on info supplied, a 'bar' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#bar

The code for the second plot

map.options <- list(
  scope = 'usa',
  projection = list(type='albers usa'),
  showlakes = TRUE,
  lakecolor = toRGB('grey')
)
borders <- list(color=toRGB("red"))

plot_ly(dat, z=dat$Population, 
        text=paste(dat$State, '<br>', dat$Abbreviation, '<br>', 
                   "Population: ", dat$Population, 
                   '<br>', "Winner: ", dat$Winnner), 
        locations=dat$Abbreviation,type = "choropleth", 
        locationmode='USA-states', 
        color = dat$Population, 
        colors='Blues', 
        marker=list(line=borders)) %>% 
  layout(title="USA Presedential Election Results in 2014", geo=map.options)

The First Plot using Plotly

## No trace type specified:
##   Based on info supplied, a 'bar' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#bar

The Second Plot using Plotly

">