Asmita DV(1NT23IS068)/Himanshu Singh(1NT23IS084)-Section B
Team 11:
Plot a dumbbell chart comparing male vs female literacy rates across states.
Step 1: Install and Load Required Libraries
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
library(tidyr)library(ggalt)
Registered S3 methods overwritten by 'ggalt':
method from
grid.draw.absoluteGrob ggplot2
grobHeight.absoluteGrob ggplot2
grobWidth.absoluteGrob ggplot2
grobX.absoluteGrob ggplot2
grobY.absoluteGrob ggplot2
library(readr)
Step 2: Read the dataset
df <-read_csv("datafile.csv")
Rows: 35 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): All India/State/Union Territory
dbl (12): 1991 - Male, 1991 - Female, 1991 - Persons, 2001 - Male, 2001 - Fe...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Create the dumbbell chart using ggplotggplot(data, aes(y = state, x = female, xend = male)) +# Set y-axis as state, x as female rate, xend as male rate# Add dumbbell segments: lines connecting female and male values for each stategeom_dumbbell(size =2, # Thickness of the dumbbell linecolour ="gray80", # Color of the connecting linecolour_x ="#FF69B4", # Color of the left point (female) - pinkcolour_xend ="#1E90FF"# Color of the right point (male) - blue ) +# Add titles and axis labelslabs(title ="Dumbbell Chart: Literacy Rate by Gender (2001)", # Main title of the chartsubtitle ="Comparing Female vs Male Literacy Rates Across Indian States", # Subtitlex ="Literacy Rate (%)", # Label for x-axisy ="State"# Label for y-axis ) +# Apply a minimal, clean themetheme_minimal()
Warning: Using the `size` aesthetic with geom_segment was deprecated in ggplot2 3.4.0.
ℹ Please use the `linewidth` aesthetic instead.