```
# 檔案下載
fL <- paste0("http://", IDPW, "140.116.183.121/~sheu/dataM/Data/cities10.txt")
# 字元確認
fwf_empty(fL)[1:2]
## $begin
## [1] 0 19
##
## $end
## [1] 17 NA
head(dta <- read.fwf(fL, width = c(19, 8), col.names = c("city", "population"), n = 10))
## city population
## 1 New York, NY 66,834.6
## 2 Kings, NY 34,722.9
## 3 Bronx, NY 31,729.8
## 4 Queens, NY 20,453.0
## 5 San Francisco, CA 16,526.2
## 6 Hudson, NJ 12,956.9
# 整理資料
new_dta <- dta %>% separate(city, into = c("city", "state"), sep = ",") %>%
mutate(city = factor(city),
population = as.numeric(population),
state = as.factor(gsub(" ", "", state)))
## Warning: package 'bindrcpp' was built under R version 3.4.3
# 繪圖
ggplot(new_dta, aes(reorder(city, -population), population, fill = state))+
geom_bar(stat="identity")+
labs(x = "city", y = "population")