This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
library(ggplot2)
Registered S3 method overwritten by 'dplyr':
method from
print.rowwise_df
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
[30m── [1mAttaching packages[22m ─────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──[39m
[30m[32m✓[30m [34mtibble [30m 3.0.0 [32m✓[30m [34mstringr[30m 1.4.0
[32m✓[30m [34mtidyr [30m 1.0.2 [32m✓[30m [34mforcats[30m 0.5.0
[32m✓[30m [34mpurrr [30m 0.3.4 [39m
[30m── [1mConflicts[22m ────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
[31mx[30m [34mdplyr[30m::[32mfilter()[30m masks [34mstats[30m::filter()
[31mx[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()[39m
library(lubridate)
Attaching package: ‘lubridate’
The following objects are masked from ‘package:dplyr’:
intersect, setdiff, union
The following objects are masked from ‘package:base’:
date, intersect, setdiff, union
library(ggplot2)
library(data.table)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
data.table 1.12.8 using 2 threads (see ?getDTthreads). Latest news: r-datatable.com
Attaching package: ‘data.table’
The following objects are masked from ‘package:lubridate’:
hour, isoweek, mday, minute, month, quarter, second, wday, week, yday, year
The following object is masked from ‘package:purrr’:
transpose
The following objects are masked from ‘package:dplyr’:
between, first, last
library(ggrepel)
library(ggmap)
Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
Please cite ggmap if you use it! See citation("ggmap") for details.
library(wordcloud)
Loading required package: RColorBrewer
library(wordcloud2)
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
library(readr)
food_master_clean <- Food_Service_Establishment_Last_Inspection %>%
summarize (COUNTY = n_distinct(COUNTY, na.rm = TRUE))
food_master_clean
food_master_clean <- Food_Service_Establishment_Last_Inspection %>%
select(COUNTY, `TOTAL # CRITICAL VIOLATIONS`) %>%
rename("VIOLATIONS" = `TOTAL # CRITICAL VIOLATIONS`) %>%
group_by(COUNTY) %>%
summarise(VIOLATIONS = sum(VIOLATIONS, na.rm=TRUE)) %>%
arrange(desc(VIOLATIONS))
print.data.frame(food_master_clean)
COUNTY VIOLATIONS
1 SARATOGA 369
2 NASSAU 351
3 WARREN 266
4 SCHENECTADY 239
5 ONONDAGA 235
6 OTSEGO 216
7 ONTARIO 211
8 ST LAWRENCE 197
9 WESTCHESTER 196
10 ESSEX 193
11 MONROE 191
12 JEFFERSON 175
13 RENSSELAER 170
14 DELAWARE 164
15 SULLIVAN 153
16 CHAUTAUQUA 136
17 GREENE 132
18 STEUBEN 121
19 CATTARAUGUS 118
20 ONEIDA 92
21 ROCKLAND 92
22 WAYNE 90
23 CLINTON 85
24 CORTLAND 76
25 ORANGE 75
26 WASHINGTON 65
27 GENESEE 61
28 FRANKLIN 58
29 OSWEGO 58
30 ALBANY 55
31 DUTCHESS 55
32 BROOME 54
33 ALLEGANY 52
34 CHENANGO 46
35 SCHOHARIE 44
36 CHEMUNG 38
37 TOMPKINS 38
38 WYOMING 38
39 FULTON 35
40 MONTGOMERY 34
41 NIAGARA 33
42 YATES 33
43 COLUMBIA 29
44 ORLEANS 29
45 SENECA 29
46 HAMILTON 27
47 MADISON 26
48 LEWIS 23
49 HERKIMER 22
50 TIOGA 22
51 SCHUYLER 19
52 LIVINGSTON 12
53 ULSTER 10
54 PUTNAM 5
55 CAYUGA 3
g <- ggplot(food_master_clean, aes(reorder(COUNTY, VIOLATIONS, sum), VIOLATIONS))
g + geom_bar(stat="identity", width = 0.2, fill="tomato2") +
labs(title="New York State Critical Violations",
subtitle="Food Service Establishment Violations Per County",
caption="Source: Open New York - Food Service Establishment: Last Inspection",
x="COUNTY")+
theme(axis.text.x = element_text(angle=89, vjust=0.5))
#ggplot(assets, aes(reorder(Currency, -Value, sum), Value)) +
#geom_col()
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.