data <- read_excel("../00_data/Raw data Roundabout.xlsx")
# Display the actual column names
names(data)
## [1] "name" "address" "town_city"
## [4] "county_area" "state_region" "country"
## [7] "lat" "long" "type"
## [10] "status" "year_completed" "approaches"
## [13] "driveways" "lane_type" "functional_class"
## [16] "control_type" "other_control_type" "previous_control_type"
# Display the first few rows
glimpse(data)
## Rows: 27,887
## Columns: 18
## $ name <chr> "Arapahoe Ave. / 4th St.", "Arapahoe Ave. / 5th …
## $ address <chr> "Boulder, Boulder Co., CO (United States)", "Bou…
## $ town_city <chr> "Boulder", "Boulder", "Belmar", "Belmar", "Seatt…
## $ county_area <chr> "Boulder Co.", "Boulder Co.", "Monmouth Co.", "M…
## $ state_region <chr> "CO", "CO", "NJ", "NJ", "WA", "WA", "WA", "WA", …
## $ country <chr> "United States", "United States", "United States…
## $ lat <dbl> -105.29160, -105.28920, -74.01782, -74.02169, -1…
## $ long <dbl> 40.01294, 40.01295, 40.17772, 40.17855, 47.65796…
## $ type <chr> "Traffic Calming Circle", "Traffic Calming Circl…
## $ status <chr> "Existing", "Existing", "Existing", "Existing", …
## $ year_completed <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1997, 0, 0, 0, 0, 2012, …
## $ approaches <dbl> 3, 3, 4, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, …
## $ driveways <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ lane_type <chr> "Single-Lane", "Single-Lane", "Single-Lane", "Si…
## $ functional_class <chr> "Other (At-Grade)", "Other (At-Grade)", "Other (…
## $ control_type <chr> "One-Way/Two-Way Stop", "One-Way/Two-Way Stop", …
## $ other_control_type <chr> "None", "None", "Unknown", "Unknown", "Unknown",…
## $ previous_control_type <chr> "Unknown", "Unknown", "Unknown", "Unknown", "Unk…
data %>%
filter(year_completed > 0) %>%
ggplot(aes(x = year_completed)) +
geom_histogram(binwidth = 5)
data %>%
filter(year_completed > 0, year_completed < 2020) %>%
ggplot(aes(x = year_completed)) +
geom_histogram(binwidth = 5)
data %>%
ggplot(aes(x = approaches, color = type)) +
geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
data %>%
filter(year_completed > 0) %>%
ggplot(aes(x = year_completed)) +
geom_histogram(binwidth = 1)
data %>%
ggplot(aes(x = approaches)) +
geom_histogram(binwidth = 1)
data %>%
ggplot(aes(x = approaches)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
data %>%
ggplot(aes(x = approaches)) +
geom_histogram() +
coord_cartesian(xlim = c(0, 10))
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
data %>%
mutate(year_completed = ifelse(year_completed == 0, NA, year_completed)) %>%
ggplot(aes(x = year_completed, y = approaches)) +
geom_point()
## Warning: Removed 16367 rows containing missing values or values outside the scale range
## (`geom_point()`).
data %>%
ggplot(aes(x = type, y = approaches)) +
geom_boxplot()
data %>%
count(type, approaches) %>%
ggplot(aes(x = type, y = factor(approaches), fill = n)) +
geom_tile()
data %>%
filter(year_completed > 0) %>%
ggplot(aes(x = year_completed, y = approaches)) +
geom_point()
data %>%
filter(year_completed > 0) %>%
ggplot(aes(x = year_completed, y = approaches)) +
geom_boxplot(aes(group = cut_width(year_completed, 5)))
## Warning: Orientation is not uniquely specified when both the x and y aesthetics are
## continuous. Picking default orientation 'x'.
mod <- lm(approaches ~ year_completed,
data = data %>% filter(year_completed > 0))
roundabouts4 <- data %>%
filter(year_completed > 0) %>%
modelr::add_residuals(mod)
roundabouts4 %>%
ggplot(aes(year_completed, resid)) +
geom_point()
roundabouts4 %>%
ggplot(aes(type, resid)) +
geom_boxplot()