chandana_vandana

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",linewidth = 1) +
  geom_point(aes(x = Female_Literacy),
               color = "red",linewidth = 3) +
  geom_point(aes(x = Male_Literacy),
               color = "blue",linewidth = 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(linewidth = 16, face = "bold"),
    axis.text.y = element_text(linewidth = 8)
  )
Warning in geom_point(aes(x = Female_Literacy), color = "red", linewidth = 3):
Ignoring unknown parameters: `linewidth`
Warning in geom_point(aes(x = Male_Literacy), color = "blue", linewidth = 3):
Ignoring unknown parameters: `linewidth`
Warning in element_text(linewidth = 8): `...` must be empty.
✖ Problematic argument:
• linewidth = 8
Warning in element_text(linewidth = 16, face = "bold"): `...` must be empty.
✖ Problematic argument:
• linewidth = 16

names(data)
[1] "State"           "Male_Literacy"   "Female_Literacy"
colnames(data) <- c("State", "Male_Literacy", "Female_literacy")