데이터: 18대부터 21대까지의 연령대(20대, 30대, 40대, 50대, 60대이상)별 진보 및 보수 득표율을 포함하며, 성별(남성, 여성) 데이터
데이터는 백분율(%)로 주어져 있으므로 소수로 변환하여 계산에 활용.
아래는 R 코드로 구현된 결과.
# 필요한 라이브러리 로드
library(tidyverse)
library(ggplot2)
# 데이터 입력 (직접 입력으로 제공된 데이터를 데이터프레임으로 변환)
data <- data.frame(
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), times = 3),
성별 = rep(c("전체", "남성", "여성"), each = 5),
`18대_진보` = c(0.658, 0.662, 0.592, 0.404, 0.278, 0.622, 0.681, 0.590, 0.390, 0.220, 0.690, 0.651, 0.520, 0.342, 0.273),
`18대_보수` = c(0.337, 0.331, 0.441, 0.625, 0.723, 0.373, 0.315, 0.405, 0.594, 0.720, 0.306, 0.347, 0.478, 0.657, 0.725),
`19대_진보` = c(0.476, 0.569, 0.524, 0.369, 0.345, 0.370, 0.590, 0.590, 0.390, 0.220, 0.560, 0.590, 0.500, 0.410, 0.250),
`19대_보수` = c(0.393, 0.355, 0.402, 0.581, 0.734, 0.520, 0.330, 0.350, 0.540, 0.740, 0.260, 0.300, 0.380, 0.540, 0.730),
`20대_진보` = c(0.478, 0.463, 0.605, 0.524, 0.328, 0.363, 0.426, 0.610, 0.550, 0.302, 0.580, 0.497, 0.600, 0.501, 0.313),
`20대_보수` = c(0.455, 0.481, 0.354, 0.439, 0.648, 0.587, 0.528, 0.352, 0.418, 0.674, 0.338, 0.438, 0.356, 0.458, 0.668),
`21대_진보` = c(0.413, 0.476, 0.727, 0.698, 0.481, 0.240, 0.379, 0.728, 0.715, 0.486, 0.581, 0.573, 0.726, 0.681, 0.475),
`21대_보수` = c(0.552, 0.504, 0.264, 0.292, 0.512, 0.741, 0.603, 0.263, 0.274, 0.504, 0.356, 0.405, 0.264, 0.309, 0.519)
)
# 1. 연령대별 진보·보수 득표율 변화 시각화
data_long <- data %>%
pivot_longer(cols = c(`18대_진보`, `19대_진보`, `20대_진보`, `21대_진보`,
`18대_보수`, `19대_보수`, `20대_보수`, `21대_보수`),
names_to = c(".value", "대"),
names_pattern = "(\\w+)_(\\w+)") %>%
mutate(대 = factor(대, levels = c("18대", "19대", "20대", "21대")))
ggplot(data_long %>% filter(성별 == "전체"), aes(x = 대, y = 진보, group = 연령대, color = 연령대)) +
geom_line() +
geom_point() +
labs(title = "연령대별 진보 득표율 변화 (18대~21대)",
x = "대선", y = "진보 득표율 (%)", color = "연령대") +
theme_minimal() +
scale_y_continuous(labels = scales::percent)
ggplot(data_long %>% filter(성별 == "전체"), aes(x = 대, y = 보수, group = 연령대, color = 연령대)) +
geom_line() +
geom_point() +
labs(title = "연령대별 보수 득표율 변화 (18대~21대)",
x = "대선", y = "보수 득표율 (%)", color = "연령대") +
theme_minimal() +
scale_y_continuous(labels = scales::percent)
# 2. 추세 분석
trend_analysis <- data %>%
filter(성별 == "전체") %>%
mutate(
진보_변화 = `21대_진보` - `18대_진보`,
보수_변화 = `21대_보수` - `18대_보수`
)
print("추세 분석 (18대 vs 21대 변화):")
print(trend_analysis[, c("연령대", "진보_변화", "보수_변화")])
# 3. 연령대별 보수-진보 격차 변화량 분석
gap_analysis <- data %>%
filter(성별 == "전체") %>%
pivot_longer(cols = c(`18대_진보`, `19대_진보`, `20대_진보`, `21대_진보`,
`18대_보수`, `19대_보수`, `20대_보수`, `21대_보수`),
names_to = c(".value", "대"),
names_pattern = "(\\w+)_(\\w+)") %>%
group_by(연령대, 대) %>%
summarise(격차 = 보수 - 진보) %>%
pivot_wider(names_from = 대, values_from = 격차) %>%
mutate(
`18_19_변화` = `19대` - `18대`,
`19_20_변화` = `20대` - `19대`,
`20_21_변화` = `21대` - `20대`
)
print("연령대별 보수-진보 격차 변화량:")
print(gap_analysis)
# 4. 연령대별 진보 득표율 변화량 계산 및 시각화
change_data <- data %>%
filter(성별 == "전체") %>%
select(연령대, `18대_진보`, `19대_진보`, `20대_진보`, `21대_진보`) %>%
pivot_longer(cols = starts_with("2"), names_to = "대", values_to = "진보_득표율") %>%
group_by(연령대) %>%
mutate(변화량 = 진보_득표율 - lag(진보_득표율, default = first(진보_득표율))) %>%
filter(!is.na(변화량))
ggplot(change_data, aes(x = 대, y = 변화량 * 100, group = 연령대, fill = 연령대)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "연령대별 진보 득표율 변화량 (18대~21대)",
x = "대선", y = "진보 득표율 변화량 (%)", fill = "연령대") +
theme_minimal() +
scale_y_continuous(labels = scales::percent)
추세 분석 (18대 vs 21대 변화):
연령대 진보_변화 보수_변화
1 20대 -0.2450 0.2150
2 30대 -0.1890 0.1730
3 40대 0.1710 -0.1770
4 50대 0.3240 -0.3330
5 60대이상 0.2060 -0.2110
연령대별 보수-진보 격차 변화량:
# A tibble: 5 × 7
연령대 `18대` `19대` `20대` `21대` `18_19_변화` `19_20_변화` `20_21_변화`
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 20대 -0.321 -0.083 -0.023 0.139 0.238 0.060 0.162
2 30대 -0.334 -0.214 -0.009 0.028 0.120 0.205 0.037
3 40대 -0.115 -0.122 -0.251 -0.463 -0.007 -0.129 -0.212
4 50대 0.251 0.212 -0.085 -0.406 -0.039 -0.297 -0.321
5 60대이상 0.448 0.389 0.320 0.031 -0.059 -0.069 -0.289
연령대별 정치적 선호도가 대선별로 변동하며, 40대 이상이 진보로 이동하는 경향이 두드러짐.
성별(남성, 여성)별로 별도 분석: 연령대별 진보·보수 득표율 변화 시각화, 추세 분석, 연령대별 보수-진보 격차 변화량 분석, 연령대별 진보 득표율 변화량 계산 및 시각화.
# 필요한 라이브러리 로드
library(tidyverse)
library(ggplot2)
# 데이터 입력 (same as before)
data <- data.frame(
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), times = 3),
성별 = rep(c("전체", "남성", "여성"), each = 5),
X18대_진보 = c(0.658, 0.662, 0.592, 0.404, 0.278, 0.622, 0.681, 0.590, 0.390, 0.220, 0.690, 0.651, 0.520, 0.342, 0.273),
X18대_보수 = c(0.337, 0.331, 0.441, 0.625, 0.723, 0.373, 0.315, 0.405, 0.594, 0.720, 0.306, 0.347, 0.478, 0.657, 0.725),
X19대_진보 = c(0.476, 0.569, 0.524, 0.369, 0.345, 0.370, 0.590, 0.590, 0.390, 0.220, 0.560, 0.590, 0.500, 0.410, 0.250),
X19대_보수 = c(0.393, 0.355, 0.402, 0.581, 0.734, 0.520, 0.330, 0.350, 0.540, 0.740, 0.260, 0.300, 0.380, 0.540, 0.730),
X20대_진보 = c(0.478, 0.463, 0.605, 0.524, 0.328, 0.363, 0.426, 0.610, 0.550, 0.302, 0.580, 0.497, 0.600, 0.501, 0.313),
X20대_보수 = c(0.455, 0.481, 0.354, 0.439, 0.648, 0.587, 0.528, 0.352, 0.418, 0.674, 0.338, 0.438, 0.356, 0.458, 0.668),
X21대_진보 = c(0.413, 0.476, 0.727, 0.698, 0.481, 0.240, 0.379, 0.728, 0.715, 0.486, 0.581, 0.573, 0.726, 0.681, 0.475),
X21대_보수 = c(0.552, 0.504, 0.264, 0.292, 0.512, 0.741, 0.603, 0.263, 0.274, 0.504, 0.356, 0.405, 0.264, 0.309, 0.519)
)
# Fix the data transformation
data_long <- data %>%
filter(성별 != "전체") %>%
pivot_longer(
cols = -c(연령대, 성별),
names_to = c("대", "category"),
names_sep = "_",
values_to = "value"
) %>%
pivot_wider(
names_from = "category",
values_from = "value"
) %>%
mutate(대 = factor(gsub("X", "", 대),
levels = c("18대", "19대", "20대", "21대"),
ordered = TRUE))
# Check the structure again
print(str(data_long))
# Now the plotting should work
# 진보 득표율 시각화
ggplot(data_long, aes(x = 대, y = 진보, group = interaction(연령대, 성별), color = 연령대, linetype = 성별)) +
geom_line(linewidth = 1) +
geom_point(size = 2) +
labs(title = "성별별 연령대별 진보 득표율 변화 (18대~21대)",
x = "대선", y = "진보 득표율", color = "연령대", linetype = "성별") +
theme_minimal(base_family = "NanumGothic") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
facet_wrap(~성별) +
theme(plot.title = element_text(hjust = 0.5, face = "bold"))
# 보수 득표율 시각화
ggplot(data_long, aes(x = 대, y = 보수, group = interaction(연령대, 성별), color = 연령대, linetype = 성별)) +
geom_line(linewidth = 1) +
geom_point(size = 2) +
labs(title = "성별별 연령대별 보수 득표율 변화 (18대~21대)",
x = "대선", y = "보수 득표율", color = "연령대", linetype = "성별") +
theme_minimal(base_family = "NanumGothic") +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
facet_wrap(~성별) +
theme(plot.title = element_text(hjust = 0.5, face = "bold"))
성별별 추세 분석 (18대 vs 21대 변화):
성별 연령대 진보_변화 보수_변화
1 남성 20대 -0.3820 0.3680
2 남성 30대 -0.3020 0.2880
3 남성 40대 0.1380 -0.1420
4 남성 50대 0.3250 -0.3200
5 남성 60대이상 0.2660 -0.2160
6 여성 20대 -0.1090 0.0500
7 여성 30대 -0.0780 0.0580
8 여성 40대 0.2060 -0.2140
9 여성 50대 0.3390 -0.3480
10 여성 60대이상 0.2020 -0.2060
출력:
성별별 연령대별 보수-진보 격차 변화량:
# A tibble: 10 × 7
성별 연령대 `18대` `19대` `20대` `21대` `18_19_변화` `19_20_변화` `20_21_변화`
1 남성 20대 -0.249 0.150 0.224 0.501 0.399 0.074 0.277
2 남성 30대 -0.366 -0.260 0.102 0.224 0.106 0.362 0.122
3 남성 40대 -0.187 -0.240 -0.258 -0.465 -0.053 -0.018 -0.207
4 남성 50대 0.190 0.150 -0.132 -0.441 -0.040 -0.282 -0.309
5 남성 60대이상 0.442 0.520 0.372 0.018 0.078 -0.148 -0.354
6 여성 20대 -0.384 -0.300 -0.224 -0.225 0.084 0.076 -0.001
7 여성 30대 -0.304 -0.290 -0.059 -0.168 0.014 0.231 -0.109
8 여성 40대 -0.042 -0.120 -0.244 -0.462 -0.078 -0.124 -0.218
9 여성 50대 0.315 0.130 -0.043 -0.372 -0.185 -0.173 -0.329
10 여성 60대이상 0.452 0.480 0.355 -0.044 0.028 -0.125 -0.399
해석: 남성 20대와 30대는 격차 증가(보수 우세), 40대 이상 격차 감소(진보 우세). 여성은 20대와 30대 격차 감소 덜 심하고, 40대 이상 격차 감소.
이 그림은 18대부터 21대까지의 선거에서 성별(남성, 여성)과 연령대(20대, 30대, 40대, 50대, 60대 이상)에 따른 진보 및 보수 득표율 변화를 나타낸 그래프. 아래는 그래프의 주요 요소와 해석:
이 그래프는 18대부터 21대까지의 선거에서 연령대와 성별에 따른 정치적 선호도의 변화를 잘 보여줌. 특히 21대에서 진보 지지의 확산이 두드러짐.
if (!requireNamespace("scales", quietly = TRUE)) install.packages("scales")
library(tidyverse)
library(ggplot2)
library(scales)
# 1. Create the original dataset
gap_data <- tibble(
연령대 = c("20대", "30대", "40대", "50대", "60대이상"),
`18대` = c(-0.321, -0.334, -0.115, 0.251, 0.448),
`19대` = c(-0.083, -0.214, -0.122, 0.212, 0.389),
`20대` = c(-0.023, -0.009, -0.251, -0.085, 0.320),
`21대` = c(0.139, 0.028, -0.463, -0.406, 0.031),
`18_19_변화` = c(0.238, 0.120, -0.007, -0.039, -0.059),
`19_20_변화` = c(0.060, 0.205, -0.129, -0.297, -0.069),
`20_21_변화` = c(0.162, 0.037, -0.212, -0.321, -0.289)
)
# 2. Prepare plot_data for the first visualization
plot_data <- gap_data %>%
select(연령대, `18대`, `19대`, `20대`, `21대`) %>%
pivot_longer(cols = -연령대, names_to = "대수", values_to = "격차") %>%
mutate(대수 = factor(대수, levels = c("18대", "19대", "20대", "21대")))
# 3. First visualization: Gap trends by age group
ggplot(plot_data, aes(x = 대수, y = 격차, group = 연령대, color = 연령대)) +
geom_line(linewidth = 1) +
geom_point(size = 3) +
geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
labs(title = "연령대별 보수-진보 격차 변화 (18대~21대)",
subtitle = "양수 = 보수 우세, 음수 = 진보 우세",
x = "대수", y = "보수-진보 격차",
color = "연령대") +
scale_y_continuous(labels = label_number(accuracy = 0.01)) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
plot.subtitle = element_text(hjust = 0.5),
legend.position = "bottom") +
scale_color_brewer(palette = "Set1")
# 4. Prepare change_data for the second visualization
change_data <- gap_data %>%
select(연령대, `18_19_변화`, `19_20_변화`, `20_21_변화`) %>%
pivot_longer(cols = -연령대, names_to = "변화_기간", values_to = "변화량") %>%
mutate(변화_기간 = factor(변화_기간,
levels = c("18_19_변화", "19_20_변화", "20_21_변화"),
labels = c("18→19대", "19→20대", "20→21대")))
# 5. Second visualization: Change amounts between elections
ggplot(change_data, aes(x = 변화_기간, y = 변화량, fill = 연령대)) +
geom_col(position = position_dodge(width = 0.8), width = 0.7) +
geom_hline(yintercept = 0, color = "black") +
labs(title = "연령대별 보수-진보 격차 변화량",
subtitle = "양수 = 보수 우세 증가/진보 우세 감소\n음수 = 보수 우세 감소/진보 우세 증가",
x = "대수 변화", y = "격차 변화량",
fill = "연령대") +
scale_y_continuous(labels = label_number(accuracy = 0.01)) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
plot.subtitle = element_text(hjust = 0.5),
legend.position = "bottom") +
scale_fill_brewer(palette = "Set2")
이 그래프는 18대부터 21대까지의 선거 기간 동안 연령대(20대, 30대, 40대, 50대, 60대 이상)별로 진보 득표율의 변화량(%)을 바 형태로 나타낸 것.
이 그래프는 연령대별로 진보 득표율의 변동성을 보여주며, 특히 50대 이상에서 감소가 두드러짐.
library(tidyverse)
library(ggplot2)
# 데이터 준비
gender_data <- tibble(
성별 = rep(c("남성", "여성"), each = 5),
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), 2),
`18대` = c(-0.249, -0.366, -0.187, 0.190, 0.442, -0.384, -0.304, -0.042, 0.315, 0.452),
`19대` = c(0.150, -0.260, -0.240, 0.150, 0.520, -0.300, -0.290, -0.120, 0.130, 0.480),
`20대` = c(0.224, 0.102, -0.258, -0.132, 0.372, -0.224, -0.059, -0.244, -0.043, 0.355),
`21대` = c(0.501, 0.224, -0.465, -0.441, 0.018, -0.225, -0.168, -0.462, -0.372, -0.044)
) %>%
pivot_longer(cols = `18대`:`21대`, names_to = "대수", values_to = "격차") %>%
mutate(대수 = factor(대수, levels = c("18대", "19대", "20대", "21대")))
# 시각화
ggplot(gender_data, aes(x = 대수, y = 격차,
group = interaction(성별, 연령대),
color = 연령대,
linetype = 성별)) +
geom_line(linewidth = 1) +
geom_point(size = 2) +
scale_linetype_manual(values = c("solid", "dashed")) +
scale_color_brewer(palette = "Set1") +
facet_wrap(~성별) +
labs(title = "성별에 따른 연령대별 정치성향 변화 (18대~21대)",
subtitle = "양수: 보수 우세, 음수: 진보 우세",
x = "대수", y = "보수-진보 격차",
color = "연령대", linetype = "성별") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
plot.subtitle = element_text(hjust = 0.5),
legend.position = "bottom")
# 변화량 데이터 준비
change_gender <- tibble(
성별 = rep(c("남성", "여성"), each = 5),
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), 2),
`18→19` = c(0.399, 0.106, -0.053, -0.040, 0.078, 0.084, 0.014, -0.078, -0.185, 0.028),
`19→20` = c(0.074, 0.362, -0.018, -0.282, -0.148, 0.076, 0.231, -0.124, -0.173, -0.125),
`20→21` = c(0.277, 0.122, -0.207, -0.309, -0.354, -0.001, -0.109, -0.218, -0.329, -0.399)
) %>%
pivot_longer(cols = `18→19`:`20→21`, names_to = "기간", values_to = "변화량") %>%
mutate(기간 = factor(기간, levels = c("18→19", "19→20", "20→21")))
# 변화량 시각화
ggplot(change_gender, aes(x = 기간, y = 변화량, fill = 연령대)) +
geom_col(position = position_dodge(0.8), width = 0.7) +
geom_hline(yintercept = 0, color = "black") +
scale_fill_brewer(palette = "Set2") +
facet_wrap(~성별) +
labs(title = "성별에 따른 보수-진보 격차 변화량",
subtitle = "양수: 보수화 진행, 음수: 진보화 진행",
x = "기간", y = "격차 변화량",
fill = "연령대") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
plot.subtitle = element_text(hjust = 0.5))
# 데이터 재구성
gender_data <- tibble(
성별 = rep(c("남성", "여성"), each = 5),
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), 2),
`18대` = c(-0.249, -0.366, -0.187, 0.190, 0.442, -0.384, -0.304, -0.042, 0.315, 0.452),
`19대` = c(0.150, -0.260, -0.240, 0.150, 0.520, -0.300, -0.290, -0.120, 0.130, 0.480),
`20대` = c(0.224, 0.102, -0.258, -0.132, 0.372, -0.224, -0.059, -0.244, -0.043, 0.355),
`21대` = c(0.501, 0.224, -0.465, -0.441, 0.018, -0.225, -0.168, -0.462, -0.372, -0.044)
) %>%
pivot_longer(cols = `18대`:`21대`, names_to = "대수", values_to = "격차")
# 시각화
ggplot(gender_data, aes(x = 대수, y = 격차, group = interaction(성별, 연령대),
color = 연령대, linetype = 성별)) +
geom_line(aes(color = 연령대, linetype = 성별), linewidth = 1) +
scale_linetype_manual(values = c("solid", "dashed")) +
scale_color_manual(values = c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd")) +
facet_wrap(~성별) +
labs(title = "성별에 따른 연령대별 정치성향 변화",
subtitle = "남성(실선) vs 여성(점선) 비교",
x = "대수", y = "보수-진보 격차") +
theme_minimal()
1. 남성의 특징:
2. 여성의 특징:
3. 성별 간 차이:
# 성별 격차 계산
gender_diff <- gender_data %>%
pivot_wider(names_from = 성별, values_from = 격차) %>%
mutate(격차차이 = 남성 - 여성)
> gender_diff %>% filter(대수 == "21대") %>% arrange(desc(격차차이))
change_gender <- tibble(
성별 = rep(c("남성", "여성"), each = 5),
연령대 = rep(c("20대", "30대", "40대", "50대", "60대이상"), 2),
`18→19` = c(0.399, 0.106, -0.053, -0.040, 0.078, 0.084, 0.014, -0.078, -0.185, 0.028),
`19→20` = c(0.074, 0.362, -0.018, -0.282, -0.148, 0.076, 0.231, -0.124, -0.173, -0.125),
`20→21` = c(0.277, 0.122, -0.207, -0.309, -0.354, -0.001, -0.109, -0.218, -0.329, -0.399)
) %>%
pivot_longer(cols = `18→19`:`20→21`, names_to = "기간", values_to = "변화량")
# 변화량 시각화
ggplot(change_gender, aes(x = 기간, y = 변화량, fill = 연령대)) +
geom_col(position = position_dodge()) +
facet_wrap(~성별) +
labs(title = "성별에 따른 변화량 비교",
subtitle = "양수: 보수화, 음수: 진보화") +
theme_minimal()
변화량 패턴:
1. 남성:
"이 결과는 한국 정치의 '성별 갈등'이 세대 내부에서도 존재함을 보여줌. 특히 20대 남녀의 정치성향 차이는 향후 정당 정체성 재편의 주요 변수가 될 수 있다."
Here's a detailed analysis and Python code to generate the plots based on the election trend data from the above data.
Conservative-Progressive Gap Trend: This line plot will show how the gap between conservative and progressive parties has changed over time, highlighting any increasing or decreasing trends.
Gap Change Between Elections: This bar plot will compare the gap between consecutive elections, showing the magnitude of change.
Final Gap in 21st Election: This bar plot will focus on the final gap observed in the 21st election, providing a clear snapshot of the current political landscape.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Sample data (replace with actual data from the webpage)
data = {
'Election': [18, 19, 20, 21],
'Year': [2012, 2017, 2022, 2025],
'Conservative': [ 41.6, 39.0, 46.6, 48.9],
'Progressive': [ 37.7, 40.2, 38.3, 36.5]
}
df = pd.DataFrame(data)
df['Gap'] = df['Conservative'] - df['Progressive']
# 1. Line plot of conservative-progressive gap over time
plt.figure(figsize=(4, 4))
sns.lineplot(x='Year', y='Gap', data=df, marker='o')
plt.title('Conservative-Progressive Gap Trend Over Time')
plt.xlabel('Year')
plt.ylabel('Gap (%)')
plt.grid(True)
plt.show()
# 2. Bar plot showing change in gap between elections
df['Gap_Change'] = df['Gap'].diff()
plt.figure(figsize=(4, 4))
sns.barplot(x='Election', y='Gap_Change', data=df.iloc[1:])
plt.title('Change in Conservative-Progressive Gap Between Elections')
plt.xlabel('Election')
plt.ylabel('Gap Change (%)')
plt.grid(True)
plt.show()
# 3. Bar plot showing final gap in the 21st election
final_gap = df[df['Election'] == 21][['Conservative', 'Progressive']]
final_gap.plot(kind='bar', figsize=(8, 5), title='Final Gap in 21st Election')
plt.xlabel('Party')
plt.ylabel('Percentage (%)')
plt.xticks(rotation=0)
plt.grid(True)
plt.show()
matplotlib
and seaborn
for visualization, which are popular Python libraries for data visualization.