LA1-final report

Author

puneeth tharun

Step 1: Install ggplot2 if not already installed

if (!require(ggplot2)) install.packages("ggplot2", dependencies = TRUE)
Loading required package: ggplot2
# Loading the ggplot2 library
library(ggplot2)

Step 2: Create sample DDP data (assuming it meant GDP data)

gdp_data <- data.frame(
  State = c("Maharashtra", "Tamil Nadu", "Uttar Pradesh", "Gujarat", "Karnataka",
            "West Bengal", "Rajasthan", "Andhra Pradesh", "Madhya Pradesh"),
  GDP = c(35.3, 24.8, 23.5, 22.5, 21.1, 16.7, 12.5, 11.6, 11.2) # in Lakh Crore (assuming based on context)
)

# Print the created data frame
print(gdp_data)
           State  GDP
1    Maharashtra 35.3
2     Tamil Nadu 24.8
3  Uttar Pradesh 23.5
4        Gujarat 22.5
5      Karnataka 21.1
6    West Bengal 16.7
7      Rajasthan 12.5
8 Andhra Pradesh 11.6
9 Madhya Pradesh 11.2

Step 3: Sort the data frame by GDP in ascending order

gdp_data <- gdp_data[order(gdp_data$GDP), ]

# Convert the State column to a factor with levels ordered by GDP
gdp_data$State <- factor(gdp_data$State, levels = gdp_data$State)

# Print the sorted data frame
print(gdp_data)
           State  GDP
9 Madhya Pradesh 11.2
8 Andhra Pradesh 11.6
7      Rajasthan 12.5
6    West Bengal 16.7
5      Karnataka 21.1
4        Gujarat 22.5
3  Uttar Pradesh 23.5
2     Tamil Nadu 24.8
1    Maharashtra 35.3

Step 4: Display the output

library(ggplot2)

ggplot(gdp_data, aes(x = State, y = GDP)) +
  geom_segment(aes(xend = State, y = 0, yend = GDP), color = "skyblue", linewidth = 1.5) +
  geom_point(color = "blue", size = 4) +
  coord_flip() +
  labs(title = "GDP Comparison Across Indian States (Sample Data)",
       x = "State",
       y = "GDP (Lakh Crore INR)") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))