Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Data Analytics branch #46

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .RData
Binary file not shown.
48 changes: 48 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
knitr::opts_chunk$set(echo = TRUE)
source("Casetrack_R.R")
myQuery = "SELECT * from `Monterey_Pub`;"
dat = dbGetQuery(dbConn, myQuery)
data.frame(dat)
summary(dat)
str(dat)
monterey = get_map(location= "monterey bay", maptype = "roadmap",scale=1, zoom = 10)
ggmap(monterey)
cities = c(dat$city)
freq = as.data.frame(table(cities))
freq = freq[freq$Freq > 1 & freq$cities != "UNKNOWN" & freq$cities != "SACRAMENTO" & freq$cities != "SAN JOSE" & freq$cities != "SAN FRANCISCO" & freq$cities != "CASTRO VALLEY" & freq$cities != "SALIANS" & freq$cities != "LOS PADRES FORE" & freq$cities != "PARAJO" & freq$cities != "SPRECKLES" & freq$cities != "PRUNDALE",]
lonlat = geocode(as.character(freq$cities))
cities = cbind(freq, lonlat)
cities$lon = round(as.numeric(cities$lon), 2)
cities$lat = round(as.numeric(cities$lat), 2)
ggmap(monterey) + geom_tile(data=cities, aes(x = lon, y = lat, alpha = Freq),
fill = "red") + theme(axis.title.y = element_text(),
axis.title.x = element_text())
crimes = dat$incident_type_primary
bat = sum(table(grep("BATTERY|ASSAULT", dat$incident_type_primary)))
theft = sum(table(grep("GRANDTHEFT|GRNDTHFT|THEFT|BURGLARY|STOLEN|ROBBED", dat$incident_type_primary)))
drugs = sum(table(grep("DRUGS|NARCOTICS|DUI|POSSESSION|MARIJUANA", dat$incident_type_primary)))
type = c("battery", "theft", "drugs")
freq = c(bat, theft, drugs)
crimeType = data.frame(type, freq)
crimeType
ggplot(crimeType, aes(type, freq)) +
geom_bar(stat="identity", position="dodge")
table(dat$`Ag Crime`[dat$`Ag Crime`=="FALSE"])
murders = dat$Crime
table(murders)
View(dat)
table(cities)
table(dat$city)
barplot(sort(dat$city, decreasing=TRUE), horiz=TRUE, main="Crimes based on
City", col=heat.colors(length(state.count)))
barplot(sort(dat$city, decreasing=TRUE), horiz=TRUE, main="Crimes based on
City", col=heat.colors(length(dat$city))
barplot(sort(dat$city, decreasing=TRUE), horiz=TRUE, main="Crimes based on
City", col=heat.colors(length(dat$city))
barplot(sort(dat$city, decreasing=TRUE), horiz=TRUE, main="Crimes based on
City", col=heat.colors(length(dat$city)))
barplot(sort(table(dat$city), decreasing=TRUE), horiz=TRUE, main="Crimes based on
City", col=heat.colors(length(dat$city)))
barplot(sort(table(freq$cities), decreasing=TRUE), horiz=TRUE, main="Crimes based on City", col=heat.colors(length(freq$cities)))
barplot(sort(table(cities), decreasing=TRUE), horiz=TRUE, main="Crimes based on City", col=heat.colors(length(cities)))
dayOfWeek = dat$day_of_week
Loading