This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
install.packages(“GGally”) install.packages(“psych”) install.packages(“readr”) install.packages(“dplyr”) install.packages(“corrplot”) install.packages(“summarytools”) install.packages(“gridExtra”) install.packages(“tidyverse”) install.packages(“ggplot2”)
summary(data) head(data) dplyr::glimpse(data) library(tidyverse) library(readr) library(ggplot2) data(mtcars) head(df) library(ggplot2)
install.packages(“rvest”) install.packages(“dplyr”) install.packages(“stringr”)
install.packages(“RSelenium”) install.packages(“dplyr”) install.packages(“rvest”) install.packages(“dplyr”) install.packages(“stringr”)
library(rvest) library(dplyr) library(stringr)
url <- “https://id.wikipedia.org/wiki/Daftar_kota_di_Indonesia_menurut_jumlah_penduduk”
web <- read_html(url)
tabel <- web %>% html_elements(“table.wikitable”) %>% .[[1]] %>% html_table(fill = TRUE)
colnames(tabel) <- c(“No”, “Kota”, “Provinsi”, “Penduduk_2024”, “Penduduk_2014”, “Perubahan”)
tabel <- tabel %>% mutate( Penduduk_2024 = as.numeric(str_replace_all(Penduduk_2024, “\D”, ““)), Penduduk_2014 = as.numeric(str_replace_all(Penduduk_2014,”\D”, ““)), Perubahan = as.numeric(str_replace_all(Perubahan,”[^\\d-]“,”“)) )
head(tabel)
web <- read_html(url)
tabel <- web %>% html_elements(“table.wikitable”) %>% .[[1]] %>% html_table(fill = TRUE)
colnames(tabel) <- c(“No”, “Kota”, “Provinsi”, “Penduduk_2024”, “Penduduk_2014”, “Perubahan”)
tabel <- tabel %>% mutate( Penduduk_2024 = as.numeric(str_replace_all(Penduduk_2024, “\D”, ““)), Penduduk_2014 = as.numeric(str_replace_all(Penduduk_2014,”\D”, ““)), Perubahan = as.numeric(str_replace_all(Perubahan,”[^\\d-]“,”“)) )
head(tabel)
library(ggplot2)
top10 <- tabel %>% arrange(desc(Penduduk_2024)) %>% slice(1:10)
ggplot(top10, aes(x = reorder(Kota, Penduduk_2024), y = Penduduk_2024)) + geom_bar(stat = “identity”, fill = “steelblue”) + coord_flip() + labs( title = “10 Kota Terpadat di Indonesia (2024)”, x = “Kota”, y = “Jumlah Penduduk” ) + theme_minimal()