library(ggplot2)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Plot a dumbbell chart comparing male vs female literacy rates across states.
library(ggplot2)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
data <- data.frame(
State = c("kaarnataka","kerala","bihar","rajasthan","tamil nadu"),
Male_Literacy = c(82,96,70,80,87),
Female_Literacy = c(68,92,55,57,78)
)data_clean <- data %>%
select(State, Male_Literacy, Female_Literacy) %>%
na.omit()ggplot(data_clean, aes(y = reorder(State, Male_Literacy))) +
geom_segment(aes(x = Female_Literacy,
xend = Male_Literacy,
yend = State),
color = "gray",size = 1) +
geom_point(aes(x = Female_Literacy),
color = "red",size = 3) +
geom_point(aes(x = Male_Literacy),
color = "blue",size = 3) +
labs(
title = "Male vs Female Literacy Rates Across States",
x = 'Literacy Rate(%)',
y = "States",
caption = "Source: data.gv.in"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 16, face = "bold"),
axis.text.y = element_text(size = 8)
)Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
names(data)[1] "State" "Male_Literacy" "Female_Literacy"
colnames(data) <- c("State", "Male_Literacy", "Female_literacy")