This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
plot(covid$date, covid$state_cases)
plot(covid$state, covid$state_cases)
This project is a data visualization of the dataset of coronavirus cases in the USA from 1/21/2020 to 4/17/2020. There are 6 variables in the dataset, including date, county (county name), state (state name), flips (flip code, which is a standard geographic identifier), cases (number of confirmed cases) and deaths (number of deaths). We created different charts to explore the dataset and created a SHINY app to allow users to interact with the data using slider and select box.
#gganimate
g<-ggplot(covid, aes(state,state_cases))+
geom_boxplot()+
theme_bw()
g
g+
transition_states(deaths,
transition_length = 11,
state_length =11) +
labs(title = "Data: {closest_state}", substitute = "Yello = number of cases, Black = number of deaths")+
# enter_fly()+# enter_fade()+ # controls events with data do not persist during transition
#exit_disappear()+
#enter_fade()+
enter_grow()+
shadow_trail(size=4,alpha=.5,colour="yellow")+
ease_aes('sine-in-out')
You can also embed plots, for example:
#gg2
g2<-ggplot(covid, aes(date,state_cases))+
geom_point(stat = "identity")+
theme_bw()
g2
g2+
transition_states(deaths,
transition_length = 11,
state_length =11) +
labs(title = "Data: {closest_state}", substitute = "Yellow = number of cases, Black = number of deaths")+
# enter_fly()+# enter_fade()+ # controls events with data do not persist during transition
#exit_disappear()+
#enter_fade()+
enter_grow()+
shadow_trail(size=4,alpha=.5,colour="yellow")+
ease_aes('sine-in-out')
##shiny
nms_data<-names(covid[ ,c(3,4,5)]) #numeric variables
cats_data<-names(covid[ ,c(1,2)]) # categorical variables
nms_data
## [1] "cases" "deaths" "state_cases"
cats_data
## [1] "date" "state"
ui <- fluidPage(
headerPanel("US Covid cases by State"),
sidebarPanel( # our widgets will be placed in a panel
sliderInput('sampleSize', 'Sample Size', min = 1, max = nrow(covid),
value = 100, step = 200, round = 0),
selectInput('x', 'X-axis Cases', choices = cats_data, selected = "State"),
selectInput('y', 'Y-axis Deaths', choices = nms_data, selected = "Deaths"),
selectInput('color', 'Color for the Points', choices = cats_data, selected = "States"),
selectInput('facet_row', 'Facet Row', c(None = '.', cats_data)),
selectInput('facet_col', 'Facet Column', c(None = '.', cats_data)),
sliderInput('plotHeight', 'Height of plot (in pixels)',
min = 100, max = 2000, value = 1000)),
mainPanel(
plotlyOutput('trendPlot', height = "400px"))
)
server <- function(input, output) {
#add reactive data information.
dataset <- reactive({
usa[sample(nrow(usa), input$sampleSize),] #sample size created in ui above
})
output$trendPlot <- renderPlotly({
# build graph with ggplot syntax
p <- ggplot(dataset(), aes_string(x = input$x, y = input$y, color = input$color)) +
geom_point()+geom_smooth(method = "lm",alpha=.2)
q<- ggplot(dataset(), aes_string(y=input$y))+ geom_bar(stat='count')+
facet_wrap(~input$color)
# if at least one facet column/row is specified, add it
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .') p <- p + facet_grid(facets)
ggplotly(p) %>%
layout(height = input$plotHeight, autosize=TRUE)
})
}
shinyApp(ui, server)
## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.