Political Attitudes
Party identification and ideological views across different groups.
Party identification and ideological views across different groups.
---
title: "{{< iconify ph chart-bar >}} Political Attitudes"
format: html
---
```{r, echo=FALSE, results='asis', message=FALSE, warning=FALSE}
dashboardr::.page_config(accessibility = TRUE)
```
Party identification and ideological views across different groups.
```{r setup}
#| echo: false
#| warning: false
#| message: false
#| error: false
#| results: 'hide'
# Load dashboardr (includes dplyr, highcharter as dependencies)
library(dashboardr)
# Global chunk options
knitr::opts_chunk$set(
echo = FALSE,
warning = FALSE,
message = FALSE,
error = FALSE,
fig.width = 12,
fig.height = 8,
dpi = 300
)
# Load data
data <- readRDS('dataset_2849obs.rds')
# Data summary
cat('Dataset loaded:', nrow(data), 'rows,', ncol(data), 'columns\n')
```
## Happiness by Political Ideology
```{r stackedbar-polviews-happy}
# Happiness by Political Ideology
result <- viz_stackedbar(
data = data,
title = "Happiness by Political Ideology",
x_var = "polviews",
stack_var = "happy",
subtitle = "How happiness varies across the political spectrum",
x_label = "Political Views",
y_label = "Percentage",
stack_label = "Happiness",
stacked_type = "percent",
x_order = c("extremely liberal", "liberal", "slightly liberal", "moderate, middle of the road", "slightly conservative", "conservative", "extremely conservative"),
stack_order = c("very happy", "pretty happy", "not too happy"),
color_palette = c("#27ae60", "#f39c12", "#e74c3c")
)
# Set chart height
if (inherits(result, 'highchart')) {
result <- highcharter::hc_size(result, height = 500)
}
# Force container height with explicit wrapper
result <- htmltools::div(
style = 'height: 500px !important; min-height: 500px !important; width: 100%; overflow: visible;',
result
)
result
```
## Mean Age by Ideology and Social Class
```{r heatmap-polviews-class}
# Mean Age by Ideology and Social Class
result <- viz_heatmap(
data = data,
title = "Mean Age by Ideology and Social Class",
x_var = "polviews",
y_var = "class",
value_var = "age",
subtitle = "Demographic patterns across political and class lines",
x_label = "Political Views",
y_label = "Social Class",
value_label = "Mean Age",
x_order = c("extremely liberal", "liberal", "slightly liberal", "moderate, middle of the road", "slightly conservative", "conservative", "extremely conservative"),
y_order = c("lower class", "working class", "middle class", "upper class"),
color_palette = c("#f7fbff", "#c6dbef", "#6baed6", "#2171b5", "#08306b"),
data_labels_enabled = TRUE,
tooltip_labels_format = "{point.value:.1f}"
)
# Set chart height
if (inherits(result, 'highchart')) {
result <- highcharter::hc_size(result, height = 450)
}
# Force container height with explicit wrapper
result <- htmltools::div(
style = 'height: 450px !important; min-height: 450px !important; width: 100%; overflow: visible;',
result
)
result
```
## Political Ideology by Gender
```{r bar-polviews-sex}
# Political Ideology by Gender
result <- viz_bar(
data = data,
title = "Political Ideology by Gender",
x_var = "polviews",
group_var = "sex",
subtitle = "Distribution of political views across genders",
x_label = "Political Views",
y_label = "Count",
x_order = c("extremely liberal", "liberal", "slightly liberal", "moderate, middle of the road", "slightly conservative", "conservative", "extremely conservative"),
color_palette = c("#3498db", "#e74c3c")
)
# Set chart height
if (inherits(result, 'highchart')) {
result <- highcharter::hc_size(result, height = 400)
}
# Force container height with explicit wrapper
result <- htmltools::div(
style = 'height: 400px !important; min-height: 400px !important; width: 100%; overflow: visible;',
result
)
result
```