# Fair warning - this is some pretty jenky code. Plotly apparently doesn't want
# us to know what happens when we make our x and y axes different colors.
# Set options for font and size
font_family = 'Arial'
font_size = 11
# Convert to interactive plotly figure with text tooltip
plot <- ggplotly(
plot_out,
tooltip = 'text',
width = 1000,
height = 800
)
plot <- plot %>% add_trace(xaxis = 'x2', showscale = FALSE)
plot <- plot %>% add_trace(xaxis = 'x3', showscale = FALSE)
plot <- plot %>% add_trace(xaxis = 'x4', showscale = FALSE)
plot <- plot %>% add_trace(xaxis = 'x5', showscale = FALSE)
plot <- plot %>%
plotly::layout(
xaxis = list(
range = list(0.5, 38.5),
tickvals = list(1, 2, 3, 4, 5),
tickfont = list(
color = '#104E8B',
family = font_family,
size = font_size
)
),
xaxis2 = list(
range = list(0.5, 38.5),
overlaying = 'x',
tickangle = -45,
ticktext = list(
'carbon fluxes',
'carbon stocks',
'embodied carbon',
'forest health',
'biodiversity',
'land use diversity',
'sensitive or rare habitats',
'water quality',
'water quantity'
),
tickvals = list(6, 7, 8, 9, 10, 11, 12, 13, 14),
tickfont = list(
color = 'darkgreen',
family = font_family,
size = font_size
)
),
xaxis3 = list(
range = list(0.5, 38.5),
overlaying = 'x',
tickangle = -45,
ticktext = list(
'educational attainment',
'access to culturally appropriate food',
'dietary quality',
'food access',
'food affordability',
'mental health tbd',
'access to care',
'housing supply and quality',
'physical health tbd'
),
tickvals = list(15, 16, 17, 18, 19, 20, 21, 22, 23),
tickfont = list(
color = 'darkred',
family = font_family,
size = font_size
)
),
xaxis4 = list(
range = list(0.5, 38.5),
overlaying = 'x',
tickangle = -45,
ticktext = list(
'total quantity exported',
'production species diversity',
'production inputs',
'total quantity food products',
'total quantity forest products',
'total quantity non-food ag products',
'value added market',
'crop failure'
),
tickvals = list(24, 25, 26, 27, 28, 29, 30, 31),
tickfont = list(
color = 'darkorange',
family = font_family,
size = font_size
)
),
xaxis5 = list(
range = list(0.5, 38.5),
overlaying = 'x',
tickangle = -45,
ticktext = list(
'social connectedness',
'community safety',
'diverse representation',
'age diversity',
'gender diversity',
'racial diversity',
'participatory governance'
),
tickvals = list(32, 33, 34, 35, 36, 37, 38),
tickfont = list(
color = 'black',
family = font_family,
size = font_size
)
)
)
plot <- plot %>% add_trace(yaxis = 'y2', showscale = FALSE)
plot <- plot %>% add_trace(yaxis = 'y3', showscale = FALSE)
plot <- plot %>% add_trace(yaxis = 'y4', showscale = FALSE)
plot <- plot %>% add_trace(yaxis = 'y5', showscale = FALSE)
plot <- plot %>%
plotly::layout(
yaxis = list(
range = list(0.5, 38.5),
tickvals = list(1, 2, 3, 4, 5),
tickfont = list(
color = '#104E8B',
family = font_family,
size = font_size
)
),
yaxis2 = list(
range = list(0.5, 38.5),
overlaying = 'y',
tickangle = 0,
ticktext = list(
'carbon fluxes',
'carbon stocks',
'embodied carbon',
'forest health',
'biodiversity',
'land use diversity',
'sensitive or rare habitats',
'water quality',
'water quantity'
),
tickvals = list(6, 7, 8, 9, 10, 11, 12, 13, 14),
tickfont = list(
color = 'darkgreen',
family = font_family,
size = font_size
)
),
yaxis3 = list(
range = list(0.5, 38.5),
overlaying = 'y',
tickangle = 0,
ticktext = list(
'educational attainment',
'access to culturally appropriate food',
'dietary quality',
'food access',
'food affordability',
'mental health tbd',
'access to care',
'housing supply and quality',
'physical health tbd'
),
tickvals = list(15, 16, 17, 18, 19, 20, 21, 22, 23),
tickfont = list(
color = 'darkred',
family = font_family,
size = font_size
)
),
yaxis4 = list(
range = list(0.5, 38.5),
overlaying = 'y',
tickangle = 0,
ticktext = list(
'total quantity exported',
'production species diversity',
'production inputs',
'total quantity food products',
'total quantity forest products',
'total quantity non-food ag products',
'value added market',
'crop failure'
),
tickvals = list(24, 25, 26, 27, 28, 29, 30, 31),
tickfont = list(
color = 'darkorange',
family = font_family,
size = font_size
)
),
yaxis5 = list(
range = list(0.5, 38.5),
overlaying = 'y',
tickangle = 0,
ticktext = list(
'social connectedness',
'community safety',
'diverse representation',
'age diversity',
'gender diversity',
'racial diversity',
'participatory governance'
),
tickvals = list(32, 33, 34, 35, 36, 37, 38),
tickfont = list(
color = 'black',
family = font_family,
size = font_size
)
)
)
# Save this for preso
htmlwidgets::saveWidget(plot, 'preso/plots/correlation_plotly.html')
# Show it
plot