# Customized mirror bar plot
plot <- plot_ly(df, x = ~male_population, y = ~age_group, type = 'bar', orientation = 'h',
name = 'Male Population', marker = list(color = '#1f77b4',
line = list(color = '#000000', width = 1)),
hoverinfo = 'x+y+name') %>%
add_trace(x = ~-female_population, y = ~age_group, type = 'bar', orientation = 'h',
name = 'Female Population', marker = list(color = '#ff7f0e',
line = list(color = '#000000', width = 1)),
hoverinfo = 'x+y+name') %>%
layout(
title = list(text = "Population Distribution: Male vs Female",
font = list(size = 24, family = "Arial, sans-serif")),
xaxis = list(title = "Population",
tickvals = seq(-7000, 7000, 1000),
ticktext = c(seq(7000, 0, -1000), seq(1000, 7000, 1000)),
gridcolor = 'rgba(200, 200, 200, 0.7)', # Gridline customization
zerolinecolor = 'rgba(100, 100, 100, 0.7)', # Zero line customization
tickfont = list(size = 12, color = 'black')),
yaxis = list(title = "Age Group",
tickfont = list(size = 14, color = 'black')),
bargap = 0.05, # Reduced gap between bars for clearer comparison
barmode = 'overlay', # Overlay bars
legend = list(x = 0.85, y = 0.95, bgcolor = 'rgba(255, 255, 255, 0.5)',
bordercolor = 'black', borderwidth = 1),
margin = list(l = 70, r = 40, b = 50, t = 80, pad = 10) # Adjusted margins for title and axis
)
# Display the customized plot
plot