Wind Rose and Map Transposition
Kaden Loring
5/21/2017
Data Frame Aquisition
Required packages.
suppressMessages(library(ggplot2))
suppressMessages(library(dplyr))
suppressMessages(library(EBImage))
suppressMessages(library(ggmap))
The wind direction (wd) variable from the WeatherLab_WR data frame will be subsetted to remove any observations recorded without a direction.
WeatherLab_WR <-read.csv("/Users/KadenLoring/Documents/SRI_17/Spreadsheets/Weather_Lab_WindRose_CSV.csv", header = T, sep = ",")
#WeatherLab_WR$wd shows blank records
Rose <- subset(WeatherLab_WR, wd != "") #remove blank records
Rose <- factor(Rose$wd) #save changes made by subset
Rose <- factor(Rose, levels = c("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW")) #reorder by direction instead of alphabetically
Construct Standard Wind Rose
The frequency wind rose is constructed with ggplot, polar coordinates, and gg_bar.
WindRose1 <- ggplot(data.frame(Rose), aes(x=Rose, fill=Rose))+ geom_bar(stat="count",width=1,colour="black",size=0.1, alpha= 0.5)+ coord_polar(theta = "x", start=6.0729, direction = 1)+
scale_color_discrete ()+ ggtitle("Frequency Wind Rose", subtitle= "March 1 - May 16, 2017 \n Saint Thomas University, Miami, FL") +
xlab("Wind Direction Recorded Every Five Minutes")+ylab("")+ guides(fill=guide_legend(title="Direction")) +
theme(plot.title = element_text(size=18, face= "bold", color = "red"), axis.title.x = element_text(size= 7), axis.text.y=element_blank(), axis.ticks.y = element_blank())
WindRose1
[图片上传中...(image-abea10-1561453217920-3)]
Construct Wind Rose with Map Appropriate Aesthetics
To ensure aesthetic quality make text color lighter, background and plot transparent, remove gridlines, and remove legend.
WindRose2 <- ggplot(data.frame(Rose), aes(x=Rose, fill=Rose))+
geom_bar(stat="count",width=1,colour="black",size=0.1, alpha= 0.5)+
coord_polar(theta = "x", start=6.075, direction = 1)+
scale_color_discrete ()+ ggtitle("Frequency Wind Rose")+
xlab("Wind Direction Recorded Every Five Minutes")+ ylab("")+ guides(fill=guide_legend(title="Direction")) + theme(plot.title = element_text(size=18, face= "bold", color = "burlywood1", vjust = -3, hjust = -0.15), axis.title.x = element_text(size= 8, color = "cornsilk1", hjust = 1.05, vjust = 1.4),
axis.text.y=element_blank(), axis.ticks.y = element_blank(), axis.text.x = element_text(colour = "cornsilk2", size= 12, face = "bold"),
legend.position = "none")+
theme(panel.grid.major = element_line(colour = NA), axis.line = element_line(colour = NA), plot.background = element_rect(fill= "transparent", colour= NA), panel.background = element_rect(fill= "transparent", colour = NA))
WindRose2
[图片上传中...(image-cc851b-1561453217920-2)]
Save as Image
To retain background transparency, save WindRose2 as a png file using ggsave function.
ggsave(WindRose2, file="WindRose2.png", bg= "transparent", device = NULL )
## Saving 7 x 5 in image
Construct Background Map
Using ggmap, create a map centered on Biscayne College weather station.
BC <- get_map(location= c(lon= -80.25405, lat= 25.92325), zoom = 17, maptype = "hybrid")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=25.92325,-80.25405&zoom=17&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false
Map_BC <- ggmap(BC, extent = "device")
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
Map_BC
[图片上传中...(image-51a95f-1561453217919-1)]
Save Map as Image
To ensure compatibility with WindRose2_Rmd, save map as image with ggsave.
ggsave(Map_BC, file= "Map_BC.png", device = NULL)
## Saving 7 x 5 in image
Read Both Images Into R
Use EBImage funcion, ‘readImage’, to import the EBImage compatible png images back into R.
WindRose2_png <- readImage("~/Desktop/WindRose2.png")
Map_BC_png <- readImage("~/Desktop/Map_BC.png")
Transpose Wind Rose onto Map
Transpose Wind Rose onto Map by image addition.
WindRoseMap <- (WindRose2_png + Map_BC_png)
display(WindRoseMap, method = "raster") #if raster is not specified the image will be displayed as an html file.
[图片上传中...(image-5c75e7-1561453217919-0)]
网友评论