[R] [ggplot2] Wind rose orientation

Thomas S. Dye tsd at tsdye.com
Fri Dec 4 07:02:21 CET 2009


Aloha Hadley,

Thanks very much for ggplot.  It's a terrific piece of work.   
Specifying width = 1 in the call to geom_bar didn't change the  
orientation of the coordinates.  If you run the example, you'll see  
that 100 is horizontal, where 90 would be on the compass.

Here is a reproducible example.  The data are shown here as the  
results of evaluating the read-data source code block, displayed as an  
Org-mode table.  A csv file is also attached (if it makes it through  
the list).

#+srcname: read-data
#+begin_src R :session
   wind.data <- read.csv("pmrf_windrose_info_new.csv")
#+end_src

#+resname: read-data
| "E"   |    90 | 4.9 | "calm"    |
| "ENE" |  67.5 | 4.9 | "calm"    |
| "NE"  |    45 | 4.9 | "calm"    |
| "NNE" |  22.5 | 4.9 | "calm"    |
| "N"   |   360 | 4.9 | "calm"    |
| "NNW" | 337.5 | 4.9 | "calm"    |
| "NW"  |   315 | 4.9 | "calm"    |
| "WNW" | 292.5 | 4.9 | "calm"    |
| "W"   |   270 | 4.9 | "calm"    |
| "WSW" | 247.5 | 4.9 | "calm"    |
| "SW"  |   225 | 4.9 | "calm"    |
| "SSW" | 202.5 | 4.9 | "calm"    |
| "S"   |   180 | 4.9 | "calm"    |
| "SSE" | 157.5 | 4.9 | "calm"    |
| "SE"  |   135 | 4.9 | "calm"    |
| "ESE" | 112.5 | 4.9 | "calm"    |
| ""    |    90 |   9 | "< 3"     |
| ""    |  67.5 |   3 | "< 3"     |
| ""    |    45 |   3 | "< 3"     |
| ""    |  22.5 |   1 | "< 3"     |
| ""    |   360 |   1 | "< 3"     |
| ""    | 337.5 | 0.5 | "< 3"     |
| ""    |   315 |   1 | "< 3"     |
| ""    | 292.5 | 0.5 | "< 3"     |
| ""    |   270 |   1 | "< 3"     |
| ""    | 247.5 | 0.5 | "< 3"     |
| ""    |   225 | 0.5 | "< 3"     |
| ""    | 202.5 | 0.5 | "< 3"     |
| ""    |   180 |   1 | "< 3"     |
| ""    | 157.5 | 0.5 | "< 3"     |
| ""    |   135 |   3 | "< 3"     |
| ""    | 112.5 |   2 | "< 3"     |
| ""    |    90 |   6 | "4 - 12"  |
| ""    |  67.5 |   4 | "4 - 12"  |
| ""    |    45 |   5 | "4 - 12"  |
| ""    |  22.5 |   2 | "4 - 12"  |
| ""    |   360 |   5 | "4 - 12"  |
| ""    | 337.5 |   4 | "4 - 12"  |
| ""    |   315 |   7 | "4 - 12"  |
| ""    | 292.5 |   4 | "4 - 12"  |
| ""    |   270 |   6 | "4 - 12"  |
| ""    | 247.5 |   2 | "4 - 12"  |
| ""    |   225 |   4 | "4 - 12"  |
| ""    | 202.5 | 1.5 | "4 - 12"  |
| ""    |   180 | 1.5 | "4 - 12"  |
| ""    | 157.5 | 1.5 | "4 - 12"  |
| ""    |   135 |   5 | "4 - 12"  |
| ""    | 112.5 | 2.5 | "4 - 12"  |
| ""    |    90 |   0 | "13 - 24" |
| ""    |  67.5 |   0 | "13 - 24" |
| ""    |    45 |   0 | "13 - 24" |
| ""    |  22.5 |   0 | "13 - 24" |
| ""    |   360 |   1 | "13 - 24" |
| ""    | 337.5 | 0.5 | "13 - 24" |
| ""    |   315 | 0.5 | "13 - 24" |
| ""    | 292.5 |   1 | "13 - 24" |
| ""    |   270 |   1 | "13 - 24" |
| ""    | 247.5 |   0 | "13 - 24" |
| ""    |   225 |   0 | "13 - 24" |
| ""    | 202.5 |   0 | "13 - 24" |
| ""    |   180 | 0.5 | "13 - 24" |
| ""    | 157.5 | 0.5 | "13 - 24" |
| ""    |   135 |   1 | "13 - 24" |
| ""    | 112.5 |   0 | "13 - 24" |
| ""    |    90 |   0 | "> 25"    |
| ""    |  67.5 |   0 | "> 25"    |
| ""    |    45 |   0 | "> 25"    |
| ""    |  22.5 |   0 | "> 25"    |
| ""    |   360 |   0 | "> 25"    |
| ""    | 337.5 |   0 | "> 25"    |
| ""    |   315 |   0 | "> 25"    |
| ""    | 292.5 |   0 | "> 25"    |
| ""    |   270 |   0 | "> 25"    |
| ""    | 247.5 |   0 | "> 25"    |
| ""    |   225 |   0 | "> 25"    |
| ""    | 202.5 |   0 | "> 25"    |
| ""    |   180 |   0 | "> 25"    |
| ""    | 157.5 |   0 | "> 25"    |
| ""    |   135 |   0 | "> 25"    |
| ""    | 112.5 |   0 | "> 25"    |


#+begin_src R :session
   library(ggplot2)
   <<read-data>>
   wind <- ggplot(wind.data, aes(x = degree, y = time, fill = wind,  
xlab(NULL), ylab(NULL)))
   wind.bar <- wind + geom_bar(stat = "identity", width = 1)
   wind.bar + coord_polar()
#+end_src

All the best,
Tom
-------------- next part --------------


On Dec 3, 2009, at 4:35 PM, hadley wickham wrote:

> Hi Thomas,
>
> I suspect you want  geom_bar(stat = "identity", width = 1), but it's
> hard to be sure without a reproducible example.
>
> Hadley
>
> On Thu, Dec 3, 2009 at 8:18 PM, Thomas S. Dye <tsd at tsdye.com> wrote:
>> Aloha all,
>>
>> I love using ggplot.  It took a while to get used to the grammar of
>> graphics, but it is starting to get easy now that I am thinking in a
>> more structured way.
>>
>> A question.  I'm making a wind rose that I'd like to be oriented with
>> due north straight up.  I've discovered that the orientation is
>> sensitive to how north is represented.  When north is represented as
>> 0, the orientation looks to be shifted just a bit counter-clockwise,
>> perhaps 10 degrees.  When north is represented as 360, the plot is
>> shifted clockwise, but past the point where north is straight up.   
>> How
>> to get north straight up?
>>
>> I've read the book (very nice) and have skimmed through the
>> documentation without finding what I need.  Any help much  
>> appreciated.
>>
>> Here is the code from my Org-babel session:
>>
>> #+begin_src R :session
>>   library(ggplot2)
>>   wind.data <- read.csv("pmrf_windrose_info_new.csv")
>>   wind <- ggplot(wind.data, aes(x = degree, y = time, fill = wind))
>>   wind.bar <- wind + geom_bar(stat = "identity")
>>   wind.bar + coord_polar()
>> #+end_src
>>
>> All the best,
>> Tom
>>
>> Thomas S. Dye, Ph.D.
>> T. S. Dye & Colleagues, Archaeologists, Inc.
>> Phone: (808) 529-0866 Fax: (808) 529-0884
>> http://www.tsdye.com
>>
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> -- 
> http://had.co.nz/



More information about the R-help mailing list