# A tibble: 6 × 11
City Address.x Zip Institution Primary Affiliation.…¹ Position.x State
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 Allendale A-1-178 M… 49401 Grand Vall… 4-year College Faculty MI
2 Allendale A-1-178 M… 49401 Grand Vall… 4-year College Faculty MI
3 Allendale 1 Campus … 4940… Grand Vall… 4-year College Faculty MI
4 Allendale 1 Campus … 4940… Grand Vall… 4-year College Faculty MI
5 Ames 2438 Osbo… 5001… Iowa State… Research Institution Faculty IA
6 Ames 2438 Osbo… 5001… Iowa State… Research Institution Faculty IA
# ℹ abbreviated name: ¹`Primary Affiliation.x`
# ℹ 4 more variables: `Work ZIP/Postal Code` <chr>, region <chr>, lat <dbl>,
# lon <dbl>
USCOTS
Useful Models
geocode using geoapify
https://www.geoapify.com/tools/geocoding-online/
Add regions and arrow end points
registra <- registr |>
filter(Institution != "Other?(not?a?CAUSE?institutional?member")|>
rename(count = n) |>
mutate(
region = case_when(
State %in% c("CT", "ME", "MA", "NH", "RI", "VT", "NJ", "NY", "PA") ~ "Northeast",
State %in% c("IL", "IN", "MI", "OH", "WI", "IA", "KS", "MN", "MO", "NE", "ND", "SD") ~ "Midwest",
State %in% c("DE", "FL", "GA", "MD", "NC", "SC", "VA", "DC", "WV", "AL", "KY", "MI", "TN", "AR", "LA", "OK", "TX", "PR") ~ "South",
State %in% c("AZ", "CO", "ID", "MT", "NV", "NM", "UT", "WY", "AK", "CA", "HI", "OR", "WA") ~ "West",
FALSE ~ "Other")
)|>
filter(!is.na(region))cause1 <- cause |>
filter(!is.na(region))Jitter the points
cause1$lat_jitter <- jitter(cause1$lat, factor = 0.0001) # Adjust factor.
cause1$lon_jitter <- jitter(cause1$lon, factor = 0.0001)Create a color palette for the regions
library(wesanderson) wes_palette(“FantasticFox1”)
pal <- colorFactor(palette = c("#7538a1", "#c7b816","#169bc7", "#c4313d"),
domain = cause1$region)Set the default lat/long for the map
lat <-38.7946
lon <- -97.5348
popup = paste0(
"<b>Institution:</b> ", cause1$Institution, "<br>",
"<b>City:</b> ", cause1$City, "<br>",
"<b>State:</b> ", cause1$State, "<br>")m <- leaflet(data = cause1) |>
addProviderTiles(providers$Thunderforest.Landscape) |>
setView(lng = lon, lat = lat, zoom = 3.5) |>
addTiles() |>
addMarkers(
lng = -93.6465,
lat = 42.0267,
label = "ISU")|>
addCircles(
color = pal(cause1$region),
popup = popup,
radius = 1500,
opacity = 0.6)|>
addLegend("bottomright", pal = pal, values = cause1$region,
title = "Region", opacity = 1) Assuming "lon" and "lat" are longitude and latitude, respectively
mcalculate distance from Iowa State U
library(sf)Warning: package 'sf' was built under R version 4.5.1
Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
df_sf <- st_as_sf(cause1, coords = c("lat", "lon"), crs = 4326)
# 4326 is WGS 84, a common CRS for geographic coordinates
df_sf <- st_set_crs(df_sf, 4326)Use Haversine formula
library(geosphere)Warning: package 'geosphere' was built under R version 4.5.1
ames_lon <- -93.616669
ames_lat <- 42.034737
cause1$distance <- distHaversine(
p1 = cbind(cause1$lon, cause1$lat),
p2 = c(ames_lon, ames_lat)
)
cause1$distance_miles <- cause1$distance/1609.344Proportion of Faculty to students for each Primary Affiliation
library(knitr)
library(kableExtra)
Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':
group_rows
cause_table <- cause1 |>
filter(`Primary Affiliation.x` != "Other")|>
mutate(type = case_when(`Primary Affiliation.x` %in% c("Research Institution", "4-year College") ~ "four-year",
`Primary Affiliation.x` == "2-year College" ~ "two-year",
TRUE ~ "Other"))|>
select(type, Position.x) |>
table()
kbl(cause_table, caption = "Two-Way Table") |>
kable_styling() |>
row_spec(row = 0, color = "#C41E3A")| Faculty | Other | Student | |
|---|---|---|---|
| four-year | 183 | 5 | 30 |
| Other | 0 | 4 | 0 |
| two-year | 7 | 0 | 0 |
table of states
state_table <- cause1 |>
group_by(State) |>
tally() |>
arrange(desc(n))
kbl(state_table, caption = "Two-Way Table") |>
kable_styling() |>
row_spec(row = 0, color = "#C41E3A")|>
column_spec(1, width = "0.5in")| State | n |
|---|---|
| IA | 33 |
| CA | 28 |
| MN | 28 |
| MI | 23 |
| NY | 19 |
| PA | 17 |
| IL | 15 |
| NC | 15 |
| MO | 9 |
| OH | 9 |
| GA | 5 |
| KY | 4 |
| OR | 4 |
| MA | 3 |
| AZ | 2 |
| FL | 2 |
| MD | 2 |
| NJ | 2 |
| WI | 2 |
| CO | 1 |
| IN | 1 |
| KS | 1 |
| NE | 1 |
| NM | 1 |
| TX | 1 |
| VA | 1 |
| VT | 1 |
| WA | 1 |