Code
options (scipen = 999 )
pacman:: p_load (
dplyr,
htmltools,
stringr,
tidyr,
reactable,
purrr,
broom,
knitr,
kableExtra,
ggplot2,
ggpubr,
psych,
tibble,
Hmisc,
reshape2,
viridisLite,
conflicted,
readr
)
# GitHub packages
pacman:: p_load_gh (
'ChrisDonovan307/projecter' ,
'Food-Systems-Research-Institute/SMdata'
)
# Functions
source ('dev/get_reactable.R' )
source ('dev/get_missing.R' )
source ('dev/data_pipeline_functions.R' )
conflicts_prefer (
dplyr:: select (),
dplyr:: filter (),
dplyr:: pull (),
dplyr:: summarize (),
stats:: lag (),
base:: setdiff (),
.quiet = TRUE
)
This page explores correlations among metrics.
Wrangling
Code
# metric crosswalk
crosswalk <- data_paper_meta %>%
select (variable_name, metric)
# Get df ready
get_str (metrics)
df <- metrics %>%
filter (variable_name %in% data_paper_meta$ variable_name) %>%
get_latest_year () %>%
filter_fips ('new' ) %>%
mutate (variable_name = str_split_i (variable_name, '_' , 1 )) %>%
left_join (crosswalk) %>%
select (- variable_name) %>%
pivot_wider (
id_cols = fips,
values_from = value,
names_from = metric
)
get_str (df)
# Get an ordered framework from which we will pull metrics in alphabetical order
# and get the counts of metrics per dimension that we will use to draw lines
# between dimensions
get_str (data_paper_meta)
ordered_framework <- data_paper_meta %>%
arrange (dimension, metric) %>%
filter (metric %in% names (df))
ordered_framework
# Get line placements to divide dimensions
# Reverse them to match alphabetical order of dimensions top to bottom
# Get cumulative sums to space them out across graph
# Then add 0.5 to each to put them in between cells
line_placements <- ordered_framework %>%
group_by (dimension) %>%
summarize (count = n ()) %>%
pull (count) %>%
rev () %>%
cumsum () %>%
{. + 0.5 }
line_placements
# Reorder our df in proper metric order
metric_order <- ordered_framework %>%
pull (metric)
df <- df %>%
select (fips, any_of (metric_order)) %>%
select (rev (everything ()))
get_str (df)
# Create matrix of values
mat <- df %>%
na.omit () %>%
select (- fips) %>%
as.matrix ()
# Get correlations
cor <- rcorr (mat, type = 'pearson' )
# Melt correlation values and rename columns
cor_r <- reshape:: melt (cor$ r) %>%
setNames (c ('var_1' , 'var_2' , 'value' ))
# Save p values
cor_p <- melt (cor$ P)
p.value <- cor_p$ value
# Make heatmap
corplot <- cor_r %>%
ggplot (aes (var_1, var_2, fill = value)) +
geom_tile () +
scale_fill_gradient2 (
low = "#762a83" ,
mid = "white" ,
high = "#1b7837" ,
midpoint = 0
) +
geom_hline (yintercept = line_placements[1 ]) +
geom_hline (yintercept = line_placements[2 ]) +
geom_hline (yintercept = line_placements[3 ]) +
geom_hline (yintercept = line_placements[4 ]) +
geom_vline (xintercept = line_placements[1 ]) +
geom_vline (xintercept = line_placements[2 ]) +
geom_vline (xintercept = line_placements[3 ]) +
geom_vline (xintercept = line_placements[4 ]) +
theme (
axis.text.x = element_text (
hjust = 1 ,
angle = 45
)
# axis.text.x = element_blank(),
# axis.ticks.x = element_blank()
) +
labs (
x = NULL ,
y = NULL ,
fill = NULL
)
ggsave (
plot = corplot,
filename = 'outputs/fig_corplot.png' ,
height = 8 ,
width = 9.5 ,
dpi = 300
)
Table
Large and unwieldy correlation matrix. Added another interactive one below that is probably easier to work with.
Code
# Latex table
df <- cor$ r %>%
as.data.frame () %>%
tibble:: rownames_to_column ('var' ) %>%
mutate (var = str_sub (var, end = 6 )) %>%
setNames (c (names (.) %>% str_sub (end = 6 )))
get_str (df)
'data.frame': 44 obs. of 45 variables:
$ var : chr "Social" "Ratio " "Racial" "Produc" "Firear" "Annual" "Acres "..
$ Social: num 1 0.2403 -0.24705 0.02889 0.35885 -0.50126 0.28993 -0.0401 0.2..
$ Ratio : num 0.2403 1 -0.00425 -0.28254 0.22364 -0.17571 0.29737 -0.36149 0..
$ Racial: num -0.24705 -0.00425 1 0.14245 -0.44591 0.36141 -0.47392 0.0185 -..
$ Produc: num 0.02889 -0.28254 0.14245 1 -0.08424 0.27511 -0.23707 0.08431 0..
$ Firear: num 0.35885 0.22364 -0.44591 -0.08424 1 -0.09665 0.53279 0.05923 0..
$ Annual: num -0.501257 -0.175707 0.361411 0.275108 -0.096648 1 -0.163404 -0..
$ Acres : num 0.2899 0.2974 -0.4739 -0.2371 0.5328 -0.1634 1 0.0978 0.3692 0..
$ Total : num -0.0401 -0.3615 0.0185 0.0843 0.0592 -0.133 0.0978 1 0.0989 0...
$ Propor: num 0.2918 0.1527 -0.2077 0.0862 0.4192 -0.0154 0.3692 0.0989 1 -0..
$ Propor: num -0.15653 -0.2332 0.00835 -0.05659 -0.14087 -0.00425 0.02816 0...
$ Crop d: num -0.189 -0.1056 0.426 0.3636 -0.5843 0.1826 -0.4921 -0.0113 -0...
$ Rental: num -0.07237 0.00767 -0.43612 -0.03304 0.47264 0.0039 0.12365 -0.2..
$ Propor: num 0.042 -0.0928 -0.0651 -0.0264 0.5459 0.1579 -0.1183 -0.1079 0...
$ Price : num -0.04524 0.18111 -0.12628 0.03086 -0.08468 -0.22502 0.20636 -0..
$ Poor m: num 0.53005 0.23827 -0.23958 0.08226 0.37336 -0.2326 0.40697 0.069..
$ Mobili: num -0.03712 0.01721 -0.04195 -0.00274 0.0761 0.03819 -0.19338 -0...
$ Limite: num 0.04309 -0.28885 0.06682 0.30974 -0.36643 -0.2862 -0.35577 -0...
$ Lackin: num 0.1858 -0.5034 0.0256 -0.045 -0.1466 -0.0537 -0.2611 0.026 -0...
$ High s: num 0.0666 -0.05356 -0.16039 -0.05997 0.3194 0.07422 0.03824 0.130..
$ Heart : num 0.014266 0.120252 -0.288339 0.002642 0.314113 -0.000869 0.0281..
$ Freque: num 0.22728 0.01309 -0.07722 0.05232 0.00903 -0.06496 -0.17607 -0...
$ Food i: num 0.4017 0.2096 -0.2402 0.0155 0.5141 -0.1046 0.2217 -0.0413 0.2..
$ Diabet: num -0.15937 -0.20595 0.33838 -0.11721 -0.39384 0.01822 -0.52207 0..
$ Weeks : num -0.28893 -0.27989 0.35194 0.1947 -0.68505 0.10635 -0.49366 0.0..
$ Tree s: num 0.3549 0.194 -0.4361 0.0193 0.4768 -0.3256 0.4304 0.011 0.2335..
$ Tree s: num 0.15891 0.16449 -0.3007 -0.05053 -0.17194 -0.1806 0.23523 -0.1..
$ Total : num 0.4467 0.2984 -0.3646 -0.0406 0.3118 -0.3379 0.7091 -0.0524 0...
$ Soil o: num 0.56395 0.49479 -0.30076 -0.08992 0.56856 -0.31767 0.64634 -0...
$ Rarefi: num 0.12662 0.19654 0.00342 0.23801 0.08376 0.08603 0.38444 0.1531..
$ Rarefi: num 0.30286 0.14656 -0.05094 -0.06177 0.20429 -0.00826 0.40105 0.0..
$ Propor: num -0.31282 -0.08265 0.36501 -0.149 -0.31513 0.01802 -0.28255 -0...
$ Land U: num -0.4369 -0.4057 0.4279 0.1716 -0.5004 0.3068 -0.6883 0.2929 -0..
$ Fuel e: num 0.01579 -0.13765 -0.32017 0.34802 0.25056 -0.00172 0.03887 0.0..
$ Availa: num 0.51552 0.24335 -0.18187 0.16248 0.4856 -0.21215 0.54338 -0.01..
$ Annual: num 0.1803 0.4033 0.0262 -0.2234 0.4482 -0.0703 0.0632 -0.0678 0.1..
$ Total : num -0.00821 -0.23446 0.03665 0.11213 0.03612 -0.06879 -0.13172 0...
$ Sales : num -0.0251 0.0894 0.3242 0.2622 0.0815 0.3199 -0.3348 -0.0665 -0...
$ Percen: num -0.1497 -0.1187 -0.1596 0.07 0.2095 -0.0178 0.1828 -0.0779 0.0..
$ Market: num -0.2958 -0.3499 0.0983 -0.1151 -0.3112 0.0791 -0.2588 -0.1364 ..
$ Land a: num -0.5459 -0.3088 0.3205 0.0932 -0.7836 0.2316 -0.6297 -0.1348 -..
$ Gini I: num -0.16631 0.25991 0.004 -0.38622 -0.19424 -0.08773 0.0393 -0.26..
$ Expens: num -0.22014 -0.54788 0.10397 0.10944 -0.18598 0.01693 -0.19555 0...
$ Change: num 0.12939 0.24946 -0.16454 -0.06042 0.22254 -0.11503 0.47954 0.0..
$ Averag: num -0.16942 0.1466 -0.27879 -0.3921 -0.22891 -0.18117 0.10661 -0...
Code
df %>%
kbl (
digits = 3 ,
format = "latex" ,
caption = 'Correlation matrix of metrics using latest available time point' ,
label = 'tab_correlations' ,
booktabs = TRUE
# longtable = TRUE
) %>%
kable_styling (
font_size = 5 ,
bootstrap_options = c (
"condensed"
)
) %>%
save_kable (
file = 'outputs/tab_correlations.tex'
)
# HTML for website
cor$ r %>%
kbl (
digits = 3 ,
format = "html"
) %>%
column_spec (1 , width = '500px' ) %>%
kable_styling (
full_width = FALSE ,
bootstrap_options = c (
"striped" ,
"hover" ,
"condensed"
)
)
Social isolation
1.000
0.240
-0.247
0.029
0.359
-0.501
0.290
-0.040
0.292
-0.157
-0.189
-0.072
0.042
-0.045
0.530
-0.037
0.043
0.186
0.067
0.014
0.227
0.402
-0.159
-0.289
0.355
0.159
0.447
0.564
0.127
0.303
-0.313
-0.437
0.016
0.516
0.180
-0.008
-0.025
-0.150
-0.296
-0.546
-0.166
-0.220
0.129
-0.169
Ratio of female to male producers
0.240
1.000
-0.004
-0.283
0.224
-0.176
0.297
-0.361
0.153
-0.233
-0.106
0.008
-0.093
0.181
0.238
0.017
-0.289
-0.503
-0.054
0.120
0.013
0.210
-0.206
-0.280
0.194
0.164
0.298
0.495
0.197
0.147
-0.083
-0.406
-0.138
0.243
0.403
-0.234
0.089
-0.119
-0.350
-0.309
0.260
-0.548
0.249
0.147
Racial diversity of producers
-0.247
-0.004
1.000
0.142
-0.446
0.361
-0.474
0.019
-0.208
0.008
0.426
-0.436
-0.065
-0.126
-0.240
-0.042
0.067
0.026
-0.160
-0.288
-0.077
-0.240
0.338
0.352
-0.436
-0.301
-0.365
-0.301
0.003
-0.051
0.365
0.428
-0.320
-0.182
0.026
0.037
0.324
-0.160
0.098
0.321
0.004
0.104
-0.165
-0.279
Producer age skew
0.029
-0.283
0.142
1.000
-0.084
0.275
-0.237
0.084
0.086
-0.057
0.364
-0.033
-0.026
0.031
0.082
-0.003
0.310
-0.045
-0.060
0.003
0.052
0.016
-0.117
0.195
0.019
-0.051
-0.041
-0.090
0.238
-0.062
-0.149
0.172
0.348
0.162
-0.223
0.112
0.262
0.070
-0.115
0.093
-0.386
0.109
-0.060
-0.392
Firearm fatalities
0.359
0.224
-0.446
-0.084
1.000
-0.097
0.533
0.059
0.419
-0.141
-0.584
0.473
0.546
-0.085
0.373
0.076
-0.366
-0.147
0.319
0.314
0.009
0.514
-0.394
-0.685
0.477
-0.172
0.312
0.569
0.084
0.204
-0.315
-0.500
0.251
0.486
0.448
0.036
0.082
0.209
-0.311
-0.784
-0.194
-0.186
0.223
-0.229
Annual population change
-0.501
-0.176
0.361
0.275
-0.097
1.000
-0.163
-0.133
-0.015
-0.004
0.183
0.004
0.158
-0.225
-0.233
0.038
-0.286
-0.054
0.074
-0.001
-0.065
-0.105
0.018
0.106
-0.326
-0.181
-0.338
-0.318
0.086
-0.008
0.018
0.307
-0.002
-0.212
-0.070
-0.069
0.320
-0.018
0.079
0.232
-0.088
0.017
-0.115
-0.181
Acres in conservation easements
0.290
0.297
-0.474
-0.237
0.533
-0.163
1.000
0.098
0.369
0.028
-0.492
0.124
-0.118
0.206
0.407
-0.193
-0.356
-0.261
0.038
0.028
-0.176
0.222
-0.522
-0.494
0.430
0.235
0.709
0.646
0.384
0.401
-0.283
-0.688
0.039
0.543
0.063
-0.132
-0.335
0.183
-0.259
-0.630
0.039
-0.196
0.480
0.107
Total animal and crop sales
-0.040
-0.361
0.019
0.084
0.059
-0.133
0.098
1.000
0.099
0.616
-0.011
-0.216
-0.108
-0.118
0.070
-0.208
-0.044
0.026
0.131
-0.267
-0.073
-0.041
0.034
0.070
0.011
-0.161
-0.052
-0.045
0.153
0.035
-0.254
0.293
0.084
-0.013
-0.068
0.345
-0.067
-0.078
-0.136
-0.135
-0.262
0.791
0.060
-0.057
Proportion of organic operations
0.292
0.153
-0.208
0.086
0.419
-0.015
0.369
0.099
1.000
-0.050
-0.568
0.267
0.123
0.445
0.135
-0.251
-0.370
-0.447
-0.277
0.048
-0.208
0.270
-0.626
-0.596
0.233
-0.072
0.292
0.383
0.156
0.228
-0.116
-0.264
0.073
0.307
0.107
-0.071
-0.221
0.049
-0.245
-0.483
-0.082
-0.054
-0.038
-0.163
Proportion of operations using precision agriculture
-0.157
-0.233
0.008
-0.057
-0.141
-0.004
0.028
0.616
-0.050
1.000
-0.117
-0.257
-0.351
0.004
0.111
0.067
-0.101
-0.145
0.047
-0.036
0.076
-0.158
0.006
0.051
-0.097
0.133
-0.039
-0.078
-0.005
0.015
-0.310
0.218
0.046
-0.135
0.138
-0.052
0.077
-0.254
-0.152
-0.095
-0.062
0.325
-0.059
-0.032
Crop diversity
-0.189
-0.106
0.426
0.364
-0.584
0.183
-0.492
-0.011
-0.568
-0.117
1.000
-0.348
-0.255
-0.198
-0.201
-0.093
0.324
0.240
-0.032
-0.317
-0.077
-0.303
0.378
0.747
-0.434
0.010
-0.275
-0.351
0.195
-0.273
0.116
0.407
-0.103
-0.249
-0.392
0.067
0.056
-0.206
0.047
0.533
-0.116
0.167
-0.065
0.043
Rental vacancy rate
-0.072
0.008
-0.436
-0.033
0.473
0.004
0.124
-0.216
0.267
-0.257
-0.348
1.000
0.495
0.238
0.199
0.435
0.042
-0.141
0.227
0.711
0.140
0.498
-0.228
-0.243
0.260
-0.256
-0.031
0.191
0.030
0.138
-0.065
-0.308
0.257
-0.018
0.239
0.038
-0.035
0.230
-0.255
-0.337
0.239
-0.220
-0.354
-0.101
Proportion uninsured
0.042
-0.093
-0.065
-0.026
0.546
0.158
-0.118
-0.108
0.123
-0.351
-0.255
0.495
1.000
-0.406
-0.017
0.305
-0.141
0.196
0.344
0.363
0.080
0.431
0.167
-0.277
0.186
-0.529
-0.360
0.031
-0.270
-0.199
-0.099
0.054
0.095
0.024
0.452
0.282
0.299
0.086
0.124
-0.251
-0.153
0.018
-0.202
-0.417
Price of a meal
-0.045
0.181
-0.126
0.031
-0.085
-0.225
0.206
-0.118
0.445
0.004
-0.198
0.238
-0.406
1.000
-0.113
-0.305
-0.053
-0.601
-0.648
-0.076
-0.349
-0.115
-0.645
-0.210
0.095
0.225
0.367
0.179
0.117
0.142
0.165
-0.313
-0.004
0.029
-0.130
-0.233
-0.300
0.173
-0.170
-0.098
0.404
-0.251
0.068
0.169
Poor mental health days
0.530
0.238
-0.240
0.082
0.373
-0.233
0.407
0.070
0.135
0.111
-0.201
0.199
-0.017
-0.113
1.000
0.461
0.197
-0.144
0.564
0.487
0.574
0.687
-0.021
-0.190
0.373
-0.005
0.383
0.617
0.404
0.352
-0.430
-0.450
0.095
0.485
0.345
0.069
0.053
0.071
-0.577
-0.673
0.048
-0.188
0.032
-0.168
Mobility disability
-0.037
0.017
-0.042
-0.003
0.076
0.038
-0.193
-0.208
-0.251
0.067
-0.093
0.435
0.305
-0.305
0.461
1.000
0.376
0.079
0.654
0.855
0.812
0.487
0.507
0.134
0.100
-0.335
-0.355
0.097
-0.142
0.055
-0.108
0.141
0.023
-0.211
0.349
0.188
0.375
-0.062
-0.315
-0.123
0.251
-0.191
-0.494
-0.121
Limited access to healthy foods
0.043
-0.289
0.067
0.310
-0.366
-0.286
-0.356
-0.044
-0.370
-0.101
0.324
0.042
-0.141
-0.053
0.197
0.376
1.000
0.326
0.129
0.187
0.496
-0.039
0.436
0.493
-0.049
-0.003
-0.241
-0.220
0.086
0.086
0.011
0.190
0.126
-0.236
-0.203
0.226
-0.051
0.202
-0.124
0.267
0.033
0.073
-0.315
-0.022
Lacking social support
0.186
-0.503
0.026
-0.045
-0.147
-0.054
-0.261
0.026
-0.447
-0.145
0.240
-0.141
0.196
-0.601
-0.144
0.079
0.326
1.000
0.274
-0.109
0.155
-0.130
0.495
0.441
-0.194
-0.015
-0.192
-0.238
-0.194
-0.032
0.068
0.157
-0.185
-0.080
-0.315
0.353
-0.048
-0.124
0.327
0.286
-0.236
0.315
-0.096
0.023
High school graduation rate
0.067
-0.054
-0.160
-0.060
0.319
0.074
0.038
0.131
-0.277
0.047
-0.032
0.227
0.344
-0.648
0.564
0.654
0.129
0.274
1.000
0.583
0.635
0.588
0.463
0.085
0.136
-0.235
-0.160
0.207
0.072
0.007
-0.289
0.038
0.039
0.110
0.240
0.269
0.271
0.078
-0.201
-0.236
-0.120
0.131
-0.158
-0.045
Heart disease prevalence
0.014
0.120
-0.288
0.003
0.314
-0.001
0.028
-0.267
0.048
-0.036
-0.317
0.711
0.363
-0.076
0.487
0.855
0.187
-0.109
0.583
1.000
0.601
0.614
0.125
-0.131
0.218
-0.302
-0.133
0.224
-0.057
0.115
-0.209
-0.101
0.155
-0.094
0.368
0.039
0.278
0.020
-0.335
-0.292
0.232
-0.287
-0.431
-0.084
Frequent physical distress
0.227
0.013
-0.077
0.052
0.009
-0.065
-0.176
-0.073
-0.208
0.076
-0.077
0.140
0.080
-0.349
0.574
0.812
0.496
0.155
0.635
0.601
1.000
0.499
0.550
0.119
0.158
-0.161
-0.241
0.178
-0.059
0.122
-0.183
0.132
0.029
-0.067
0.274
0.190
0.348
-0.097
-0.310
-0.108
0.171
-0.051
-0.340
-0.035
Food insecurity rate, overall
0.402
0.210
-0.240
0.016
0.514
-0.105
0.222
-0.041
0.270
-0.158
-0.303
0.498
0.431
-0.115
0.687
0.487
-0.039
-0.130
0.588
0.614
0.499
1.000
0.023
-0.350
0.312
-0.301
0.139
0.540
0.141
0.079
-0.315
-0.358
0.109
0.418
0.533
0.208
0.318
0.124
-0.251
-0.592
0.212
-0.091
-0.150
-0.235
Diabetes prevelance
-0.159
-0.206
0.338
-0.117
-0.394
0.018
-0.522
0.034
-0.626
0.006
0.378
-0.228
0.167
-0.645
-0.021
0.507
0.436
0.495
0.463
0.125
0.550
0.023
1.000
0.520
-0.375
-0.287
-0.601
-0.254
-0.245
-0.157
0.129
0.573
-0.296
-0.358
0.017
0.389
0.273
-0.160
0.243
0.469
0.075
0.316
-0.283
0.079
Weeks of extreme drought
-0.289
-0.280
0.352
0.195
-0.685
0.106
-0.494
0.070
-0.596
0.051
0.747
-0.243
-0.277
-0.210
-0.190
0.134
0.493
0.441
0.085
-0.131
0.119
-0.350
0.520
1.000
-0.424
0.016
-0.353
-0.389
0.168
-0.122
0.131
0.464
-0.268
-0.337
-0.464
0.279
-0.028
-0.183
0.087
0.588
-0.005
0.284
-0.247
0.053
Tree species diversity
0.355
0.194
-0.436
0.019
0.477
-0.326
0.430
0.011
0.233
-0.097
-0.434
0.260
0.186
0.095
0.373
0.100
-0.049
-0.194
0.136
0.218
0.158
0.312
-0.375
-0.424
1.000
0.205
0.458
0.296
0.223
0.025
-0.110
-0.468
0.510
0.338
0.169
-0.127
-0.131
0.205
-0.262
-0.616
-0.198
-0.301
0.170
-0.251
Tree size diversity
0.159
0.164
-0.301
-0.051
-0.172
-0.181
0.235
-0.161
-0.072
0.133
0.010
-0.256
-0.529
0.225
-0.005
-0.335
-0.003
-0.015
-0.235
-0.302
-0.161
-0.301
-0.287
0.016
0.205
1.000
0.570
0.129
0.269
-0.039
-0.217
-0.413
0.160
0.239
-0.244
-0.365
-0.298
0.151
0.111
0.073
-0.140
-0.357
0.280
0.292
Total ecosystem carbon per acre
0.447
0.298
-0.365
-0.041
0.312
-0.338
0.709
-0.052
0.292
-0.039
-0.275
-0.031
-0.360
0.367
0.383
-0.355
-0.241
-0.192
-0.160
-0.133
-0.241
0.139
-0.601
-0.353
0.458
0.570
1.000
0.592
0.483
0.201
-0.189
-0.792
0.062
0.674
-0.123
-0.253
-0.369
0.146
-0.066
-0.533
-0.016
-0.311
0.526
0.081
Soil organic carbon
0.564
0.495
-0.301
-0.090
0.569
-0.318
0.646
-0.045
0.383
-0.078
-0.351
0.191
0.031
0.179
0.617
0.097
-0.220
-0.238
0.207
0.224
0.178
0.540
-0.254
-0.389
0.296
0.129
0.592
1.000
0.269
0.297
-0.283
-0.648
-0.235
0.736
0.353
-0.003
-0.093
-0.013
-0.364
-0.663
0.088
-0.261
0.266
0.052
Rarefied richness of plants
0.127
0.197
0.003
0.238
0.084
0.086
0.384
0.153
0.156
-0.005
0.195
0.030
-0.270
0.117
0.404
-0.142
0.086
-0.194
0.072
-0.057
-0.059
0.141
-0.245
0.168
0.223
0.269
0.483
0.269
1.000
0.317
-0.253
-0.330
0.107
0.301
-0.291
-0.011
-0.180
0.294
-0.317
-0.348
-0.198
-0.091
0.205
-0.142
Rarefied richness of animals
0.303
0.147
-0.051
-0.062
0.204
-0.008
0.401
0.035
0.228
0.015
-0.273
0.138
-0.199
0.142
0.352
0.055
0.086
-0.032
0.007
0.115
0.122
0.079
-0.157
-0.122
0.025
-0.039
0.201
0.297
0.317
1.000
0.005
-0.249
0.029
0.152
-0.073
0.065
-0.225
0.058
-0.505
-0.344
0.150
-0.058
-0.004
-0.083
Proportion of invasive species
-0.313
-0.083
0.365
-0.149
-0.315
0.018
-0.283
-0.254
-0.116
-0.310
0.116
-0.065
-0.099
0.165
-0.430
-0.108
0.011
0.068
-0.289
-0.209
-0.183
-0.315
0.129
0.131
-0.110
-0.217
-0.189
-0.283
-0.253
0.005
1.000
0.201
-0.179
-0.206
-0.286
-0.077
-0.297
-0.048
0.253
0.329
0.081
0.003
-0.173
0.087
Land Use Diversity
-0.437
-0.406
0.428
0.172
-0.500
0.307
-0.688
0.293
-0.264
0.218
0.407
-0.308
0.054
-0.313
-0.450
0.141
0.190
0.157
0.038
-0.101
0.132
-0.358
0.573
0.464
-0.468
-0.413
-0.792
-0.648
-0.330
-0.249
0.201
1.000
-0.046
-0.710
-0.213
0.255
0.224
-0.329
0.164
0.612
-0.153
0.519
-0.418
-0.033
Fuel expenses
0.016
-0.138
-0.320
0.348
0.251
-0.002
0.039
0.084
0.073
0.046
-0.103
0.257
0.095
-0.004
0.095
0.023
0.126
-0.185
0.039
0.155
0.029
0.109
-0.296
-0.268
0.510
0.160
0.062
-0.235
0.107
0.029
-0.179
-0.046
1.000
0.002
0.089
-0.161
0.024
0.185
-0.212
-0.214
-0.296
-0.130
-0.110
-0.363
Available water storage
0.516
0.243
-0.182
0.162
0.486
-0.212
0.543
-0.013
0.307
-0.135
-0.249
-0.018
0.024
0.029
0.485
-0.211
-0.236
-0.080
0.110
-0.094
-0.067
0.418
-0.358
-0.337
0.338
0.239
0.674
0.736
0.301
0.152
-0.206
-0.710
0.002
1.000
0.252
-0.089
-0.083
0.130
-0.049
-0.572
-0.176
-0.175
0.390
-0.284
Annual precipitation
0.180
0.403
0.026
-0.223
0.448
-0.070
0.063
-0.068
0.107
0.138
-0.392
0.239
0.452
-0.130
0.345
0.349
-0.203
-0.315
0.240
0.368
0.274
0.533
0.017
-0.464
0.169
-0.244
-0.123
0.353
-0.291
-0.073
-0.286
-0.213
0.089
0.252
1.000
-0.117
0.421
-0.088
-0.203
-0.459
0.173
-0.261
-0.099
-0.278
Total indemnities
-0.008
-0.234
0.037
0.112
0.036
-0.069
-0.132
0.345
-0.071
-0.052
0.067
0.038
0.282
-0.233
0.069
0.188
0.226
0.353
0.269
0.039
0.190
0.208
0.389
0.279
-0.127
-0.365
-0.253
-0.003
-0.011
0.065
-0.077
0.255
-0.161
-0.089
-0.117
1.000
0.137
0.068
-0.063
0.047
0.190
0.539
0.091
-0.005
Sales from agritourism and recreation
-0.025
0.089
0.324
0.262
0.082
0.320
-0.335
-0.067
-0.221
0.077
0.056
-0.035
0.299
-0.300
0.053
0.375
-0.051
-0.048
0.271
0.278
0.348
0.318
0.273
-0.028
-0.131
-0.298
-0.369
-0.093
-0.180
-0.225
-0.297
0.224
0.024
-0.083
0.421
0.137
1.000
-0.057
0.032
0.054
0.098
-0.088
-0.095
-0.313
Percent change in wages
-0.150
-0.119
-0.160
0.070
0.209
-0.018
0.183
-0.078
0.049
-0.254
-0.206
0.230
0.086
0.173
0.071
-0.062
0.202
-0.124
0.078
0.020
-0.097
0.124
-0.160
-0.183
0.205
0.151
0.146
-0.013
0.294
0.058
-0.048
-0.329
0.185
0.130
-0.088
0.068
-0.057
1.000
0.088
-0.089
-0.038
-0.157
0.220
0.110
Market channel ratio
-0.296
-0.350
0.098
-0.115
-0.311
0.079
-0.259
-0.136
-0.245
-0.152
0.047
-0.255
0.124
-0.170
-0.577
-0.315
-0.124
0.327
-0.201
-0.335
-0.310
-0.251
0.243
0.087
-0.262
0.111
-0.066
-0.364
-0.317
-0.505
0.253
0.164
-0.212
-0.049
-0.203
-0.063
0.032
0.088
1.000
0.528
-0.064
0.220
0.071
0.097
Land and building value per acre
-0.546
-0.309
0.321
0.093
-0.784
0.232
-0.630
-0.135
-0.483
-0.095
0.533
-0.337
-0.251
-0.098
-0.673
-0.123
0.267
0.286
-0.236
-0.292
-0.108
-0.592
0.469
0.588
-0.616
0.073
-0.533
-0.663
-0.348
-0.344
0.329
0.612
-0.214
-0.572
-0.459
0.047
0.054
-0.089
0.528
1.000
0.069
0.260
-0.179
0.375
Gini Index
-0.166
0.260
0.004
-0.386
-0.194
-0.088
0.039
-0.262
-0.082
-0.062
-0.116
0.239
-0.153
0.404
0.048
0.251
0.033
-0.236
-0.120
0.232
0.171
0.212
0.075
-0.005
-0.198
-0.140
-0.016
0.088
-0.198
0.150
0.081
-0.153
-0.296
-0.176
0.173
0.190
0.098
-0.038
-0.064
0.069
1.000
-0.116
0.014
0.261
Expenses per operation
-0.220
-0.548
0.104
0.109
-0.186
0.017
-0.196
0.791
-0.054
0.325
0.167
-0.220
0.018
-0.251
-0.188
-0.191
0.073
0.315
0.131
-0.287
-0.051
-0.091
0.316
0.284
-0.301
-0.357
-0.311
-0.261
-0.091
-0.058
0.003
0.519
-0.130
-0.175
-0.261
0.539
-0.088
-0.157
0.220
0.260
-0.116
1.000
-0.044
0.055
Change in agricultural establishments
0.129
0.249
-0.165
-0.060
0.223
-0.115
0.480
0.060
-0.038
-0.059
-0.065
-0.354
-0.202
0.068
0.032
-0.494
-0.315
-0.096
-0.158
-0.431
-0.340
-0.150
-0.283
-0.247
0.170
0.280
0.526
0.266
0.205
-0.004
-0.173
-0.418
-0.110
0.390
-0.099
0.091
-0.095
0.220
0.071
-0.179
0.014
-0.044
1.000
0.266
Average weekly wages
-0.169
0.147
-0.279
-0.392
-0.229
-0.181
0.107
-0.057
-0.163
-0.032
0.043
-0.101
-0.417
0.169
-0.168
-0.121
-0.022
0.023
-0.045
-0.084
-0.035
-0.235
0.079
0.053
-0.251
0.292
0.081
0.052
-0.142
-0.083
0.087
-0.033
-0.363
-0.284
-0.278
-0.005
-0.313
0.110
0.097
0.375
0.261
0.055
0.266
1.000
Long Table
Longer format table that is interactive and shows p values.
Code
# Create long table with p values and stars
tab <- cor_r %>%
rename (cor = value) %>%
inner_join (cor_p, by = join_by (var_1 == Var1, var_2 == Var2)) %>%
rename (p = value) %>%
mutate (sig = ifelse (p < 0.05 , '*' , '' ))
# Save to outputs
write_csv (
tab,
'outputs/table_metric_correlations_long.csv'
)
tab %>%
get_reactable (
defaultColDef = colDef (
format = colFormat (digits = 3 )
)
)
Back to top