You are on page 1of 3

library (ggplot2)

library (corrplot)
library (maps)
FD <- read.csv( file = "FlightDelays.csv")
FI <- read.csv( file = 'FlightInfo.csv')
#Merging the columns from two data sets
MyData <- data.frame(FD, FI[, 2:7])
#Converting one database into 1:0
MyData$delay <- ifelse( MyData$delay == 'delayed', 1,0)
# Only selecting flights from particular airports
MyData1 <- MyData[MyData$dest == 'JFK'| MyData$dest == 'LGA'| MyData$dest == 'EWR', ]
# Give numbers to Sunday and Monday
MyData1$dayweek <- ifelse(MyData1$dayweek == '7' | MyData1$dayweek == '1', 1, 0)
# mt cars with annotate & all
MyMtCars <- mtcars
# Cor Matrix
CorMatrix <- cor(MyMtCars[c( 1,3,4, 5)])
corrplot (CorMatrix)
# GG plot
ggplot ( MyMtCars, aes(MyMtCars$wt, MyMtCars$mpg, color = MyMtCars$cyl))+
geom_point() + theme_bw()+stat_smooth(method = 'lm', , se = FALSE)+ annotate( "rect", xmin = 5.1 ,
xmax= 5.5, ymin = 0, ymax = 40, alpha = 0.1, fill = 'blue') +annotate( "segment", x = 5.1, xend = 5.41, y =
5, yend = 10.3, color = 'blue', size =1 , arrow =arrow())+ annotate( 'text', x = 4.7, y = 4.4, label= "licon
continental")+ labs(x = 'WT', y = 'mpg', title = "mpg vs wt")
ggplot ( MyMtCars, aes(MyMtCars$mpg))+ geom_histogram( binwidth = 2, color = "black", fill = 'blue',
aes( y = ..density..))+geom_density( stat = 'density', fill = 'black' , alpha = 0.2)+ theme_bw()
#Maps
world_map <- map_data('world')
eastasia_map <- map_data("world", region=c("Japan", "China", "North Korea", "South Korea, "))
#Drawing Map of the Eastern Asia
ggplot(eastasia_map, aes(x= long, y = lat, group = group, fill = region))+
geom_polygon(color = 'black')+
scale_fill_brewer(palette="Set2")+
theme_bw()
#Drawing World Map
ggplot(world_map,aes(x=long, y=lat, group=group)) +
geom_polygon(colour="black", fill = "white") +
scale_fill_brewer(palette="Set2")+
theme_bw()
CrimeData <- read.csv(file = 'crime_map.csv')
states.map <- map_data("state")
# When you have to do mapping use this
ggplot(CrimeData, aes(map_id = region, fill=Assault)) +
geom_map(map = states.map, colour="black") +
scale_fill_gradient2(low="#559999", mid="grey90", high="#BB650B",
midpoint=median(CrimeData$Assault)) +
expand_limits(x = CrimeData$long, y = CrimeData$lat)

You might also like