Skip to content

Commit

Permalink
new function for constellation creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssafowers committed Nov 25, 2019
1 parent f919df4 commit c5cc5ee
Show file tree
Hide file tree
Showing 126 changed files with 21,799 additions and 10,669 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions compare_state_country.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#run through streamgraph.R first to get counts of topic by month for whole
#country

library(tidyverse)
library(janitor)
library(muckrakr)
Expand Down
616 changes: 616 additions & 0 deletions constellation_coocurrence_function.R

Large diffs are not rendered by default.

25 changes: 8 additions & 17 deletions constellation_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ library(muckrakr)
library(sf)
library(nngeo)

loc <- "data/working"
protest <- clean_names(read_csv(file.path(loc, "protest_additional_tags.csv")))
loc <- "data/final"
protest <- clean_names(read_csv(file.path(loc, "protest_nov1_addtl_tags.csv")))
#protest <- clean_names(read_csv(file.path(loc, "protest_all_states.csv")))

place <- clean_names(read_csv(file.path(loc, "all_county_cbsa_summary.csv")))
place <- clean_names(read_csv(file.path(loc, "nov1_all_county_cbsa_summary.csv")))

constellation <- function(list = protest, place_summary = place, topic, write_loc = "constellations"){
tag <- untangle(protest, "tags", pattern = ";")
summary <- tag %>% group_by(location_id, location_name) %>%
summarise(protest_count = n(), topic_protest = sum(get(topic)), internal_point_latitude = mean(internal_point_latitude), internal_point_longitude = mean(internal_point_longitude)) %>%
summarise(protest_count = n(), topic_protest = sum(get(topic)), internal_point_latitude = mean(latitude), internal_point_longitude = mean(longitude)) %>%
mutate(perc_topic = topic_protest/protest_count)

##adding in population
Expand All @@ -26,7 +26,7 @@ constellation <- function(list = protest, place_summary = place, topic, write_lo
#getting criteria for inclusion in constellation
t_sum <- filter(summary, topic_protest > 0)

crit_10k <- unname(quantile(t_sum$topic_per_10k, .25))
crit_10k <- unname(quantile(t_sum$topic_per_10k, .4))
crit_perctopic <- unname(quantile(t_sum$perc_topic, .5))
crit_count <- unname(quantile(t_sum$topic_protest, .8))

Expand Down Expand Up @@ -111,26 +111,17 @@ constellation <- function(list = protest, place_summary = place, topic, write_lo
}

constellation(topic = "collective_bargaining")
constellation(topic = "guns")
constellation(topic = "police")
constellation(topic = "for_white_supremacy")
constellation(topic = "race_confed")
constellation(topic = "immigration")
constellation(topic = "executive")
constellation(topic = "education")
constellation(topic = "environment")
constellation(topic = "healthcare")
constellation(topic = "charlottesville")
constellation(topic = "for_racial_justice")
constellation(topic = "for_abortion_rights")
constellation(topic = "against_abortion_rights")
constellation(topic = "lgbtq")
constellation(topic = "supreme_court")
constellation(topic = "against_greater_gun_control")
constellation(topic = "guns")
constellation(topic = "women")
constellation(topic = "race_confed")
constellation(topic = "police_criminal_justice")
constellation(topic = "freedom_of_speech")
constellation(topic = "voting")
constellation(topic = "police")



Expand Down
Binary file modified constellations/.DS_Store
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
location_id,location_name,protest_count,topic_protest,internal_point_latitude,internal_point_longitude,perc_topic,pop,topic_per_10k,id
32820,"Memphis, TN-MS-AR",78,6,35.154290366666665,-89.91262927435898,0.07692307692307693,1347576,0.04452439046109459,20
41180,"St. Louis, MO-IL",187,16,38.63965343101604,-90.26547390160428,0.0855614973262032,2805850,0.05702371830283158,28
26980,"Iowa City, IA",52,5,41.6688774,-91.5889245,0.09615384615384616,171470,0.29159619758558347,15
19780,"Des Moines-West Des Moines, IA",63,5,41.668044293650794,-93.57644839841271,0.07936507936507936,645100,0.07750736319950396,9
33460,"Minneapolis-St. Paul-Bloomington, MN-WI",265,21,45.00210212226415,-93.30116941622641,0.07924528301886792,3592669,0.05845236508011175,22
40420,"Rockford, IL",29,5,42.3373957,-89.1612053,0.1724137931034483,338252,0.14781878599387438,27
16980,"Chicago-Naperville-Elgin, IL-IN-WI",386,38,41.92133177512953,-87.8070955919689,0.09844559585492228,9520784,0.039912679460010855,7
33340,"Milwaukee-Waukesha-West Allis, WI",75,8,43.017716708,-87.547369004,0.10666666666666667,1575151,0.050788781519993956,21
29620,"Lansing-East Lansing, MI",68,7,42.603329102941174,-84.38076236176471,0.10294117647058823,480353,0.1457261638836439,17
11460,"Ann Arbor, MI",83,6,42.2523272,-83.8446336,0.07228915662650602,369208,0.16251002145132282,2
19820,"Detroit-Warren-Dearborn, MI",259,31,42.417101405405404,-83.29177782432433,0.11969111969111969,4321704,0.07173096537847108,10
22420,"Flint, MI",19,5,43.0210768,-83.7063718,0.2631578947368421,407673,0.12264731782580646,12
19380,"Dayton, OH",71,10,39.759415609859154,-84.22021011408451,0.14084507042253522,803713,0.12442252396066755,8
38300,"Pittsburgh, PA",173,18,40.43270033121387,-79.92217578265895,0.10404624277456648,2330283,0.07724383690736275,25
15380,"Buffalo-Cheektowaga-Niagara Falls, NY",92,14,42.8292776847826,-78.77970853695653,0.15217391304347827,1129660,0.12393109431156277,5
42540,"Scranton--Wilkes-Barre--Hazleton, PA",45,7,41.27572774666667,-75.84649676888888,0.15555555555555556,555645,0.12597971726552026,32
35300,"New Haven-Milford, CT",108,17,41.3497173,-72.9002037,0.1574074074074074,857794,0.19818278048109453,23
44140,"Springfield, MA",122,9,42.25282312295082,-72.65173956721311,0.07377049180327869,629506,0.14296924890310816,35
24640,"Greenfield Town, MA",33,5,42.5845038,-72.5917921,0.15151515151515152,70787,0.7063443852684815,14
39300,"Providence-Warwick, RI-MA",111,11,41.79659436036036,-71.48685305675676,0.0990990990990991,1617057,0.06802481297814486,26
14460,"Boston-Cambridge-Newton, MA-NH",415,43,42.426534771084334,-71.06648177277108,0.10361445783132531,4844597,0.08875867280601461,4
15540,"Burlington-South Burlington, VT",64,8,44.469511096874996,-73.066909978125,0.125,218881,0.36549540617961357,6
44060,"Spokane-Spokane Valley, WA",75,7,47.63268786,-117.40108899866667,0.09333333333333334,563958,0.12412271835845931,34
28420,"Kennewick-Richland, WA",37,7,46.27782055675676,-119.41778656756756,0.1891891891891892,290570,0.2409058058299205,16
42660,"Seattle-Tacoma-Bellevue, WA",251,23,47.47549453625498,-121.8930187498008,0.09163346613545817,3884469,0.05921015201820378,33
21660,"Eugene, OR",84,6,43.9283286,-122.8976901,0.07142857142857142,375617,0.15973717909466292,11
41860,"San Francisco-Oakland-Hayward, CA",453,55,37.70787360794702,-122.45526016401766,0.12141280353200883,4710693,0.11675564508236899,31
41500,"Salinas, CA",41,6,36.240107,-121.3155723,0.14634146341463414,435477,0.13777995163923698,29
23420,"Fresno, CA",40,6,36.7610058,-119.6550193,0.15,986542,0.060818495309880365,13
12540,"Bakersfield, CA",51,5,35.3466288,-118.7295064,0.09803921568627451,888988,0.0562437288242361,3
37100,"Oxnard-Thousand Oaks-Ventura, CA",43,5,34.3587415,-119.1331432,0.11627906976744186,850802,0.05876807999981195,24
31080,"Los Angeles-Long Beach-Anaheim, CA",554,54,34.080789156859204,-118.1542577364621,0.09747292418772563,13298709,0.040605445235323216,19
41740,"San Diego-Carlsbad, CA",278,23,33.0236041,-116.7761174,0.08273381294964029,3325468,0.06916319748077564,30
29820,"Las Vegas-Henderson-Paradise, NV",89,12,36.2142575,-115.013812,0.1348314606741573,2183310,0.054962419445704,18
11260,"Anchorage, AK",61,5,61.301033450819666,-149.32256917213115,0.08196721311475409,400647,0.12479813901015109,1
46520,"Urban Honolulu, HI",52,6,21.4613654,-158.201974,0.11538461538461539,986429,0.06082546234954569,36
19380,"Dayton, OH",75,10,39.767466666666664,-84.1462,0.13333333333333333,803713,0.12442252396066755,5
11460,"Ann Arbor, MI",90,7,42.271588888888886,-83.7244,0.07777777777777778,369208,0.1895950250265433,1
19820,"Detroit-Warren-Dearborn, MI",271,32,42.41526568265683,-83.15709963099631,0.11808118081180811,4321704,0.07404486748745402,6
22420,"Flint, MI",23,9,43.004260869565215,-83.69278260869565,0.391304347826087,407673,0.22076517208645166,8
29620,"Lansing-East Lansing, MI",77,7,42.729610389610386,-84.53876623376624,0.09090909090909091,480353,0.1457261638836439,12
33340,"Milwaukee-Waukesha-West Allis, WI",81,10,43.03843209876543,-87.93748148148148,0.12345679012345678,1575151,0.06348597689999246,13
26980,"Iowa City, IA",58,6,41.663275862068964,-91.53810344827586,0.10344827586206896,171470,0.34991543710270023,10
41180,"St. Louis, MO-IL",194,19,38.64118556701031,-90.22667525773196,0.0979381443298969,2805850,0.06771566548461251,18
33460,"Minneapolis-St. Paul-Bloomington, MN-WI",285,23,44.96612280701754,-93.20209122807017,0.08070175438596491,3592669,0.06401925699250334,14
49660,"Youngstown-Warren-Boardman, OH-PA",63,6,41.148650793650795,-80.66093650793651,0.09523809523809523,541875,0.11072664359861592,27
38300,"Pittsburgh, PA",181,19,40.41624309392265,-79.93314364640884,0.10497237569060773,2330283,0.08153516117999403,16
15380,"Buffalo-Cheektowaga-Niagara Falls, NY",98,15,42.909806122448984,-78.84855102040817,0.15306122448979592,1129660,0.13278331533381726,3
42540,"Scranton--Wilkes-Barre--Hazleton, PA",51,8,41.30421568627451,-75.80511764705882,0.1568627450980392,555645,0.14397681973202314,22
35300,"New Haven-Milford, CT",113,17,41.342230088495576,-72.90945132743363,0.1504424778761062,857794,0.19818278048109453,15
44140,"Springfield, MA",128,10,42.2362265625,-72.5877265625,0.078125,629506,0.1588547210034535,25
39300,"Providence-Warwick, RI-MA",118,11,41.77379661016949,-71.36549152542372,0.09322033898305085,1617057,0.06802481297814486,17
14460,"Boston-Cambridge-Newton, MA-NH",443,44,42.41779232505643,-71.06360045146727,0.09932279909706546,4844597,0.09082282798754986,2
15540,"Burlington-South Burlington, VT",73,8,44.48183561643835,-73.196,0.1095890410958904,218881,0.36549540617961357,4
44060,"Spokane-Spokane Valley, WA",76,7,47.66132894736842,-117.40469736842105,0.09210526315789473,563958,0.12412271835845931,24
28420,"Kennewick-Richland, WA",37,7,46.24935135135135,-119.21275675675676,0.1891891891891892,290570,0.2409058058299205,11
42660,"Seattle-Tacoma-Bellevue, WA",265,24,47.56762264150944,-122.33397735849056,0.09056603773584905,3884469,0.06178450645377785,23
21660,"Eugene, OR",89,9,44.03806741573034,-123.15021348314608,0.10112359550561797,375617,0.2396057686419944,7
41860,"San Francisco-Oakland-Hayward, CA",495,61,37.79507070707071,-122.32105858585858,0.12323232323232323,4710693,0.12949262454590016,21
41500,"Salinas, CA",47,7,36.629829787234044,-121.73806382978724,0.14893617021276595,435477,0.16074327691244314,19
23420,"Fresno, CA",40,6,36.732075,-119.764225,0.15,986542,0.060818495309880365,9
41740,"San Diego-Carlsbad, CA",293,23,32.79875767918089,-117.14565870307167,0.07849829351535836,3325468,0.06916319748077564,20
46520,"Urban Honolulu, HI",60,7,21.332833333333333,-157.87568333333334,0.11666666666666667,986429,0.0709630394078033,26
Binary file not shown.
Loading

0 comments on commit c5cc5ee

Please sign in to comment.