Dear group, how to draw a wind rose plot?example plot attached

845 views
Skip to first unread message

Vivian Zhang

unread,
Mar 13, 2013, 8:23:32 PM3/13/13
to ggp...@googlegroups.com
Dear group

I read a post about visualizing wind direction and speed at a location using wind rose.
It is on http://www.r-bloggers.com/visualising-diurnal-wind-climatologies-2/

I found the first plot in green(called wind rose) is great and want to learn it. Does anyone know how to do it? Unfortunately, the post author just used this plot as an his reference and didn't generate this plot.

Thank you very much!


Best,
Vivian
Wind_rose_plot.jpg

Janesh Devkota

unread,
Mar 13, 2013, 10:05:17 PM3/13/13
to Vivian Zhang, Ggplot2

Vivian,

 

This might be a starting point for you. It is not the exact replica of the link you provided but will keep you get going.

 

library(gcookbook)

library(ggplot2)

ggplot(wind, aes(x=DirCat, fill=SpeedCat)) +

  geom_histogram(binwidth=15, origin=-7.5) +

  coord_polar() +

  scale_x_continuous(limits=c(0,360))

 

Janesh




--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ista Zahn

unread,
Mar 13, 2013, 10:32:53 PM3/13/13
to Vivian Zhang, ggp...@googlegroups.com
Hi Vivian,

I'm not familiar with wind rose plots, but here is what I came up with:

############################
## From the metvurst blog ##
############################
## SET URL FOR DATA DOWNLOAD
url <- "http://www.bom.gov.au/ntc/IDO70004/IDO70004_"

## YEARS TO BE DOWNLOADED
yr <- 1993:2012

## READ DATA FOR ALL YEARS FROM URL INTO LIST
fijilst <- lapply(seq(yr), function(i) {
read.csv(paste(url, yr[i], ".csv", sep = ""), na.strings = c(-9999, 999))
})

## TURN LIST INTO COMPLETE DATAFRAME AND CONVERT NA STRINGS TO NAs
fiji <- do.call("rbind", fijilst)
fiji[fiji == -9999] <- NA
fiji[fiji == -9999] <- NA
fiji[fiji == 999] <- NA
############################

library(ggplot2)
library(plyr)

# bin wind direction twice--a large bin and a smaller one

fiji$WD.cat <- cut(fiji$Wind.Direction, breaks=seq(0, 360, by = 10))
fiji$WD.cat2 <- cut(fiji$Wind.Direction, breaks=seq(0, 360, by = 40))


# calculate number and average speed by the larger bin
fiji2 <- ddply(fiji,
c("WD.cat"),
function(DF) {
data.frame(WD.cat2 = unique(DF$WD.cat2),
Wind.Speed = mean(DF$Wind.Speed, na.rm=TRUE),
count = length(na.omit(DF$Wind.Speed)))
})

# plot using polar coordinates

ggplot(na.omit(fiji2), aes(x=WD.cat2, y=count, fill=Wind.Speed)) +
geom_bar(size=.8, stat="identity") +
coord_polar()


HTH,
Ista
Reply all
Reply to author
Forward
0 new messages