library(ggmap)
## Loading required package: ggplot2
## ℹ Google's Terms of Service: ]8;;https://mapsplatform.google.com<https://mapsplatform.google.com>]8;;
## Stadia Maps' Terms of Service: ]8;;https://stadiamaps.com/terms-of-service/<https://stadiamaps.com/terms-of-service/>]8;;
## OpenStreetMap's Tile Usage Policy: ]8;;https://operations.osmfoundation.org/policies/tiles/<https://operations.osmfoundation.org/policies/tiles/>]8;;
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(ggplot2)
library(maps)
library(sf)
## Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(osrm)
## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
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(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
india_map <- map_data("world", region = "India")
ggplot(india_map, aes(x= long, y= lat, group= group)) +
geom_polygon(fill= "lightgreen", color= "black") + coord_fixed(1) +theme_void()

library(readr)
list_industries <- read_csv("data/list_industries.csv")
## Rows: 259 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Industry Name, Industry Category, City, State
## dbl (1): Sl No.
##
## ℹ 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.
View(list_industries)
list_industries$City <- tolower(list_industries$City)
# Create a frequency table of cities
city_counts <- table(list_industries$City)
# Create a bar plot for the frequency distribution of cities
barplot(city_counts,
main = "Frequency Distribution of Cities",
xlab = "City",
ylab = "Frequency",
las = 2, # Rotate x-axis labels if needed
cex.names = 0.7) # Adjust label size if needed

library(readr)
lat_long_factories <- read_csv("data/lat_long_factories.csv")
## Rows: 73 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): City, Latitude, Longitude
##
## ℹ 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.
View(lat_long_factories)
# Load required library
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ stringr 1.5.0
## ✔ tidyr 1.2.1 ✔ forcats 0.5.2
## ✔ purrr 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::map() masks maps::map()
# Convert Latitude and Longitude columns to numeric after removing the suffixes
lat_long_factories <- lat_long_factories %>%
mutate(
Latitude = as.numeric(gsub("'b0 N", "", Latitude)),
Longitude = as.numeric(gsub("'b0 E", "", Longitude))
)
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
# Check the updated tibble
head(lat_long_factories)
## # A tibble: 6 × 3
## City Latitude Longitude
## <chr> <dbl> <dbl>
## 1 Talcher 21.0 85.2
## 2 Dharmasala 20.5 85.1
## 3 Kansbahal 22.1 84.9
## 4 Kalunga 22.1 85.9
## 5 BANEI 21.0 84.6
## 6 Ramachandrapur 20.4 85.9
lat_long_factories$City <- tolower(lat_long_factories$City)
merged <- left_join(list_industries, lat_long_factories, by= "City")
sorted_cities <- sort(unique(merged$City))
print(sorted_cities)
## [1] "angul" "arda" "aska"
## [4] "athagarh" "atharbanki" "badbil"
## [7] "badmal" "balanda" "balasore"
## [10] "balda" "balgopalpur" "bali"
## [13] "bamra" "banei" "bansapal"
## [16] "barbil" "barbil tehsil" "bardol"
## [19] "barhamusa" "basundhara" "belpahar"
## [22] "berhampur" "bhadrak" "bhadrasahi"
## [25] "bhubaneswar" "bhurkamunda" "bijabahal"
## [28] "bilaimunda" "birangatoli" "biringatoli"
## [31] "birkera" "bonai" "bonaigarh"
## [34] "brajrajnagar" "brarajnagar" "burkhamunda"
## [37] "burla" "chandrabalishyampur" "chatrapur"
## [40] "chhendipada road" "chintapokhari" "choudwar"
## [43] "cuttack" "damanjodi" "danagadi"
## [46] "dengula" "deojhar" "dharmasala"
## [49] "dhenkanal" "duburi" "gobardhan"
## [52] "godabandha" "guali" "gurudijhatia"
## [55] "gurundupali" "hemgiri" "hirakud"
## [58] "jagatsinghpur" "jajang" "jajanga"
## [61] "jajpur" "jakhapura" "jakhpura"
## [64] "jayantpur" "jeypore(rs)" "jhagarpur"
## [67] "jharkhan" "jharsguda" "jharsuguda"
## [70] "jhimani" "jiabahal kalunga" "jindal nagar"
## [73] "joda" "jspur" "kalakala"
## [76] "kalarangiatta" "kaliapani" "kalinganagar"
## [79] "kalunga" "kaniha" "kansa"
## [82] "kansbahal" "karakolha" "katapali"
## [85] "keonjhar" "kesharamal" "kharagprasad"
## [88] "khetrarajpur" "khondbond" "khordha"
## [91] "koira" "kolabira" "koraput"
## [94] "korian" "kuarmunda" "kucheipdar"
## [97] "kususpanga" "lahunipara" "lakhanpur"
## [100] "lapanga" "mancheshwar" "mancheswar"
## [103] "matkambeda" "meramandali" "meramunduli"
## [106] "nayabazar" "nayakote" "palaspanga"
## [109] "paradeep" "paradeepgarh" "podbahal"
## [112] "pratapgarh" "purunapani" "rajamunda"
## [115] "rajgangpur" "ramachandrapur" "ramvikata"
## [118] "randia" "rayagada" "rengali"
## [121] "rourkela" "rugudihi" "sambalpur"
## [124] "sanaghumda" "sialbahali" "sikirdi"
## [127] "suakati" "sukinda (tk)" "sukruli"
## [130] "sundargarh" "sundergarh" "tainser"
## [133] "talapada" "talcher" "tehsil-barbil"
## [136] "tensa" "titilagarh"
merged <- merged %>%
arrange(City)
merged <- merged %>%
select(-1)
library(leaflet)
write_csv(merged, "./data/mergedwithlat.csv")
mergedwithlat <- read_csv("data/mergedwithlat.csv")
## Rows: 280 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Industry Name, Industry Category, City, State
## dbl (2): Latitude, Longitude
##
## ℹ 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.
View(mergedwithlat)
mergedwithlat <- mergedwithlat %>%
select(1:5)
# Count the frequency of each city
city_counts <- mergedwithlat %>%
group_by(City) %>%
summarise(count = n())
# Select only the Latitude, Longitude, and City Count columns
new_dataset <- left_join(city_counts,lat_long_factories, by= "City")
new_dataset <- na.omit(new_dataset)
# Calculate the center latitude and longitude of the dataset
center_lat <- mean(new_dataset$Latitude)
# Create a leaflet map centered around the calculated latitude
m <- leaflet() %>%
setView(lng = 85.1, lat = center_lat, zoom = 7) %>%
addTiles()
# Add all latitude points to the map at once
m <- addCircleMarkers(map = m,
lng = new_dataset$Longitude, # Fixed longitude for all points
lat = new_dataset$Latitude,
radius = 5,
color = "orange",
fillOpacity = 0.5,
popup = paste("Latitude:", new_dataset$Latitude))
m