# Load required libraries
library(bangladesh)
library(ggplot2)
library(leaflet)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
# Load dengue dataset
dengue <- read.csv("E:/Dr.Nirob/meleria/dataset.csv", stringsAsFactors = FALSE)
# Load upazila shapefile from bangladesh package
data("map_upazila")
upazila <- map_upazila
# Filter for Dhaka district
dhaka_map <- upazila[upazila$District == "Dhaka", ]
# Aggregate dengue cases by area
dhaka_cases <- aggregate(Outcome ~ Area, data = dengue, sum)
colnames(dhaka_cases)[1] <- "Upazila" # rename to match shapefile column
# Merge dengue case data with shapefile
dhaka_map$Cases <- dhaka_cases$Outcome[match(dhaka_map$Upazila, dhaka_cases$Upazila)]
dhaka_map$Cases[is.na(dhaka_map$Cases)] <- 0 # fill NAs with 0
# Plot static map using ggplot2
ggplot(dhaka_map) +
geom_sf(aes(fill = Cases)) +
scale_fill_gradient(low = "green", high = "red") +
theme_minimal() +
labs(title = "Dengue Cases in Dhaka District", fill = "Number of Cases")

# Interactive map using leaflet
pal <- colorNumeric(palette = "Reds", domain = dhaka_map$Cases)
leaflet(dhaka_map) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(
fillColor = ~pal(Cases),
color = "black", weight = 1, opacity = 1, fillOpacity = 0.7,
highlightOptions = highlightOptions(
weight = 3, color = "blue", fillOpacity = 0.9, bringToFront = TRUE),
label = ~paste0(Upazila, ": ", Cases, " case(s)"),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px", direction = "auto")
) %>%
addLegend(pal = pal, values = ~Cases, title = "Number of Dengue Cases", position = "bottomright")
# Gender distribution pie chart
gender_count <- as.data.frame(table(dengue$Gender))
colnames(gender_count) <- c("Gender", "Count")
plot_ly(gender_count, labels = ~Gender, values = ~Count, type = 'pie') %>%
layout(title = 'Gender Distribution of Dengue Patients',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
# Bar chart of dengue cases by area
area_cases <- aggregate(Outcome ~ Area, data = dengue, sum)
plot_ly(area_cases, x = ~Area, y = ~Outcome, type = "bar",
text = ~Outcome, textposition = "auto") %>%
layout(title = "Dengue Cases by Area (Dhaka)",
xaxis = list(title = "Area"), yaxis = list(title = "Positive Cases"))
# Pie chart by house type
house_cases <- aggregate(Outcome ~ HouseType, data = dengue, sum)
plot_ly(house_cases, labels = ~HouseType, values = ~Outcome, type = 'pie') %>%
layout(title = "Cases by House Type")
# Pie chart by area type
area_type_cases <- aggregate(Outcome ~ AreaType, data = dengue, sum)
plot_ly(area_type_cases, labels = ~AreaType, values = ~Outcome, type = 'pie') %>%
layout(title = "Dengue Cases by Area Type")