library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.2
##
## 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(tidyr)
library(readxl)
## Warning: package 'readxl' was built under R version 3.4.2
library(readxl)
tallb=read_excel("tallestbuildings.xlsx")
Citycounts=tallb%>%group_by(City)%>%summarize(number=length(City))
ggplot(Citycounts,aes(reorder(City,-number),number))+geom_bar(stat = "identity",fill="red")+coord_flip()
colnames(tallb)[colnames(tallb)=="Height (ft)"] <- "Height"
Citymean=tallb%>%group_by(City)%>%summarize(number=mean(Height))
ggplot(Citymean,aes(reorder(City,-number),number))+geom_bar(stat = "identity",fill="5")+coord_flip()
library(countrycode)
## Warning: package 'countrycode' was built under R version 3.4.2
newtallb=tallb %>% separate(City, c("City", "Country"), sep="[:punct:]")
## Warning: Too many values at 100 locations: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
## 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...
newtallb$Country=countrycode(newtallb$Country, "iso2c", "country.name", warn = TRUE, custom_dict = NULL, custom_match = NULL, origin_regex = FALSE)
Countrycounts=newtallb%>%group_by(Country)%>%summarize(number=length(Country))
ggplot(Countrycounts,aes(reorder(Country,-number),number))+geom_bar(stat = "identity",fill="red")+coord_flip()
Countrymean=newtallb%>%group_by(Country)%>%summarize(number=mean(Height))
ggplot(Countrymean,aes(reorder(Country,-number),number))+geom_bar(stat = "identity",fill="5")+coord_flip()
Countrymeancount=newtallb%>%group_by(Country)%>%summarize(Buildingcounts=n(), Countrymean=mean(Height))
ggplot(Countrymeancount,aes(reorder(Country,-Countrymean),Countrymean, fill=Buildingcounts))+geom_bar(stat = "identity", position="dodge")+coord_flip()+labs(list(title= "Countries ranked by the mean height of tall buildings", x="", y="Countrymean"))+theme_classic()
Usemean=newtallb%>%group_by(Use)%>%summarize(number=mean(Height))
ggplot(Usemean,aes(reorder(Use,number),number))+geom_bar(stat = "identity",fill="gold")+coord_flip()