Warning: package 'ggplot2' was built under R version 4.2.3
ℹ Google's Terms of Service: <https://mapsplatform.google.com>
Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(readr)
Warning: package 'readr' was built under R version 4.2.3
library(lubridate)
Warning: package 'lubridate' was built under R version 4.2.3
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
library(plotly)
Warning: package 'plotly' was built under R version 4.2.3
Attaching package: 'plotly'
The following object is masked from 'package:ggmap':
wind
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(dplyr)
Warning: package 'dplyr' was built under R version 4.2.3
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
df<-read_csv("C:/Users/g_a09/Desktop/Universidad/Visualizacion de datos/R/ggmap/RDataSets/RDataSets/violent_crimes.csv", col_names =TRUE)
Rows: 878049 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (6): Category, Descript, DayOfWeek, PdDistrict, Resolution, Address
dbl (2): X, Y
dttm (1): Dates
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(df)
# A tibble: 6 × 9
Dates Category Descript DayOfWeek PdDistrict Resolution Address
<dttm> <chr> <chr> <chr> <chr> <chr> <chr>
1 2015-05-13 23:53:00 WARRANTS WARRANT… Wednesday NORTHERN ARREST, B… OAK ST…
2 2015-05-13 23:53:00 OTHER OF… TRAFFIC… Wednesday NORTHERN ARREST, B… OAK ST…
3 2015-05-13 23:33:00 OTHER OF… TRAFFIC… Wednesday NORTHERN ARREST, B… VANNES…
4 2015-05-13 23:30:00 LARCENY/… GRAND T… Wednesday NORTHERN NONE 1500 B…
5 2015-05-13 23:30:00 LARCENY/… GRAND T… Wednesday PARK NONE 100 Bl…
6 2015-05-13 23:30:00 LARCENY/… GRAND T… Wednesday INGLESIDE NONE 0 Bloc…
# ℹ 2 more variables: X <dbl>, Y <dbl>
Warning: The dot-dot notation (`..level..`) was deprecated in ggplot2 3.4.0.
ℹ Please use `after_stat(level)` instead.
ℹ The deprecated feature was likely used in the ggmap package.
Please report the issue at <https://github.com/dkahle/ggmap/issues>.
Warning: Removed 4 rows containing non-finite outside the scale range
(`stat_density2d()`).
Warning: The `guide` argument in `scale_*()` cannot be `FALSE`. This was deprecated in
ggplot2 3.3.4.
ℹ Please use "none" instead.
ℹ The deprecated feature was likely used in the ggmap package.
Please report the issue at <https://github.com/dkahle/ggmap/issues>.
Se puede observar una concentracion bastante grande en la parte noreste de la ciudad, donde se ve mas presencia de casos violentos en el 2007 y 2008.
df_filtered <- df_new %>%filter(Year >=2010& Year <=2015)gg <-ggmap(myMap, extent ="device") +stat_density2d(data = df_filtered, aes(x = X, y = Y, fill = ..level.., alpha = ..level..),size =0.01, bins =16, geom ="polygon") +scale_fill_gradient(low ="green", high ="red") +scale_alpha(range =c(0, 0.3), guide =FALSE) +facet_wrap(~Year, ncol =3)theme(plot.title =element_text(size =20)) +theme(plot.margin =margin(1, 1, 1, 1, "cm"))
con respecto a las graficas anteriores, se puede observar una “mejora” en cuanto a los crimenes violentos se trata, donde se comienzan a reducir pero nuevamente desde el 2013 y 2014 tienen un aumento significativo para luego disminuir en el 2015, pero lo que comparten todos los años es la localizacion, la mayoria de casos violentos se dan en la zona noreste, por ende seria lo mas recomndable poner a disposicion alta densidad de policias de rapida respuesta para atender los casos de esa zona.