getwd
getwd()
shiny::runApp()
runApp()
devtools::install_github("dkahle/ggmap")
library(ggmap)
library(dplyr)
# Wczytywanie klucza API Map Google (musisz zdoby? w?asny klucz).
source("api_key.R")
register_google(key = google_key)
# Wczytywanie danych z serwisu GitHub.
data_url <- "https://raw.githubusercontent.com/washingtonpost/data-police-shootings/master/fatal-police-shootings-data.csv"
shootings <- read.csv(data_url, stringsAsFactors = F) %>%
mutate(
address = paste0(city, ", ", state)
) %>%
filter(as.Date(date) >= as.Date("2018-01-01"))
# Pobieranie adresów.
shootings[, c("long", "lat")] <- geocode(shootings$address)
# Zastępowanie wartości.
shootings$race[shootings$race == "W"] <- "Biała (nielatynoska)"
shootings$race[shootings$race == "B"] <- "Czarna nielatynoska"
shootings$race[shootings$race == "A"] <- "Azjatycka"
shootings$race[shootings$race == "N"] <- "Rdzenno-ameryka?ska"
shootings$race[shootings$race == "H"] <- "Latynoska"
shootings$race[shootings$race == "O"] <- "Inna"
shootings$race[shootings$race == ""] <- "Nieznana"
shootings$gender[shootings$gender == "M"] <- "Mężczyzna"
shootings$gender[shootings$gender == "F"] <- "Kobieta"
shootings$gender[shootings$gender == ""] <- "Nieznana"
# Zapisywanie pliku CSV zawierającego dane.
write.csv(shootings, "police-shootings.csv", row.names = FALSE)
# Geocode addresses: based on the following blog post
# http://www.storybench.org/geocode-csv-addresses-r/
# Use dev version of ggmaps so that you can set the Google Maps API key
# devtools::install_github("dkahle/ggmap")
library(ggmap)
library(dplyr)
# Load and google maps API key (you'll need to get your own)
source("api_key.R")
register_google(key = "AIzaSyCddEv8JWp9Eh750lBq9SDKvRXBr9zISUo")
# Load data from GitHub
data_url <- "https://raw.githubusercontent.com/washingtonpost/data-police-shootings/master/fatal-police-shootings-data.csv"
shootings <- read.csv(data_url, stringsAsFactors = F) %>%
mutate(
address = paste0(city, ", ", state)
) %>%
filter(as.Date(date) >= as.Date("2018-01-01"))
# Get addresses
shootings[, c("long", "lat")] <- geocode(shootings$address)
# Replace values
shootings$race[shootings$race == "W"] <- "White, non-Hispanic"
shootings$race[shootings$race == "B"] <- "Black, non-Hispanic"
shootings$race[shootings$race == "A"] <- "Asian"
shootings$race[shootings$race == "N"] <- "Native American"
shootings$race[shootings$race == "H"] <- "Hispanic"
shootings$race[shootings$race == "O"] <- "Other"
shootings$race[shootings$race == ""] <- "Unknown"
shootings$gender[shootings$gender == "M"] <- "Male"
shootings$gender[shootings$gender == "F"] <- "Female"
shootings$gender[shootings$gender == ""] <- "Unknown"
# Write a CSV file containing the data
write.csv(shootings, "police-shootings.csv", row.names = FALSE)
install.packages("ggmap")
install.packages("ggmap")
install.packages("ggmap")
# Geocode addresses: based on the following blog post
# http://www.storybench.org/geocode-csv-addresses-r/
# Use dev version of ggmaps so that you can set the Google Maps API key
# devtools::install_github("dkahle/ggmap")
library(ggmap)
library(dplyr)
# Load and google maps API key (you'll need to get your own)
source("api_key.R")
register_google(key = "AIzaSyCddEv8JWp9Eh750lBq9SDKvRXBr9zISUo")
# Load data from GitHub
data_url <- "https://raw.githubusercontent.com/washingtonpost/data-police-shootings/master/fatal-police-shootings-data.csv"
shootings <- read.csv(data_url, stringsAsFactors = F) %>%
mutate(
address = paste0(city, ", ", state)
) %>%
filter(as.Date(date) >= as.Date("2018-01-01"))
# Get addresses
shootings[, c("long", "lat")] <- geocode(shootings$address)
# Replace values
shootings$race[shootings$race == "W"] <- "White, non-Hispanic"
shootings$race[shootings$race == "B"] <- "Black, non-Hispanic"
shootings$race[shootings$race == "A"] <- "Asian"
shootings$race[shootings$race == "N"] <- "Native American"
shootings$race[shootings$race == "H"] <- "Hispanic"
shootings$race[shootings$race == "O"] <- "Other"
shootings$race[shootings$race == ""] <- "Unknown"
shootings$gender[shootings$gender == "M"] <- "Male"
shootings$gender[shootings$gender == "F"] <- "Female"
shootings$gender[shootings$gender == ""] <- "Unknown"
# Write a CSV file containing the data
write.csv(shootings, "police-shootings.csv", row.names = FALSE)
shiny::runApp()
