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:
library(tidyverse) library(mosaic) library(moderndive) library(dplyr)
data(package = “moderndive”)
data(“DD_vs_SB”, package = “moderndive”)
head(DD_vs_SB) summary(DD_vs_SB) str(DD_vs_SB)
county_stats <- favstats(~shops | county , data = DD_vs_SB , na.rm=TRUE) print(county_stats)
coffeeshop_stats <- favstats(~median_income | shop_type , data = DD_vs_SB , na.rm=TRUE) print(coffeeshop_stats)
data1 <- data.frame(DD_vs_SB)
income <- quantile(data1$median_income,probs= c(0.25, 0.75), na.rm= TRUE) print(income)
# Chart
# Plotting
filtered_dd <- DD_vs_SB %>% filter(shop_type == “dunkin_donuts”) aggregate_dd <- aggregate(shops ~ county, data = filtered_dd, FUN = count) print(aggregate_dd)
filtered_sb <- DD_vs_SB %>% filter(shop_type == “starbucks”) aggregate_sb <- aggregate(shops ~ county, data = filtered_sb, FUN = count) print(aggregate_sb)
gf_point(shops ~ county,color = “red” , data = aggregate_dd) + labs(x = “county”, y = “shops”, title = “Dunkin Donuts shops by county”)
gf_point(shops ~ county,color = “black” , data = aggregate_dd) + labs(x = “county”, y = “shops”, title = “Starbucks shops by county”)