Hi Hadley,

Thank you very much!

The idea of plotting a wind rose must be fairly common.  I wonder if  
it would make sense to have a switch that would wrap data around the  
ends of a continuous scale?

All the best,
Tom

On Dec 6, 2009, at 7:51 PM, hadley wickham wrote:

> Hi Tom,
>
> The problem was that the bars have width 22.5, so setting the limits
> to c(0, 360) chopped off the last bar.  To get around that, you needed
> to add half a bar width (11.25) to the start and end limits, and then
> rotate the polar coordinate system so that 0 lines up again.
>
> ggplot(wind.data, aes(x = degree, y = time, fill = wind)) +
> geom_bar(stat = "identity", aes(width = 22.5)) +
> scale_x_continuous(limits = c(0 + 11.25, 360 + 11.25), breaks = c(90,
> 180, 270, 360)) +
> coord_polar(start = 11.25 / 180 * pi) +
> scale_fill_brewer(pal = "Blues")
>
> Or now I've correctly identified the problem, we don't need to
> manually set the limits:
>
> ggplot(wind.data, aes(x = degree, y = time, fill = wind)) +
> geom_bar(stat = "identity", aes(width = 22.5)) +
> scale_x_continuous(breaks = c(90, 180, 270, 360)) +
> coord_polar(start = 11.25 / 180 * pi) +
> scale_fill_brewer(pal = "Blues")
>
>
> Hadley
>
> On Sun, Dec 6, 2009 at 7:30 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>> Hi Hadley,
>> I don't know if you saw the message below.  I've worked with
>> scale_continuous() a bit in the interim to see if changing the  
>> limits would
>> bring back the 16th bar, but without success.  If I don't add in
>> scale_continuous(), then the 16th bar is shown.
>> Is this a ggplot2 bug?
>> I apologize for my persistence on this, but I'm working under a  
>> project
>> deadline.  I'm captivated by the grammar of graphics and would like  
>> to produce
>> all my graphs with ggplot2.  If there is a bug that swallows the  
>> 16th bar,
>> though, then I'll make my wind rose with another package and wait  
>> patiently
>> until ggplot2 plots the full compass.
>> Thanks again for a terrific software package.
>> All the best,
>> Tom
>> Begin forwarded message:
>>
>> From: "Thomas S. Dye" <tsd@tsdye.com>
>> Date: December 3, 2009 9:42:27 PM HST
>> To: hadley wickham <h.wickham@gmail.com>
>> Cc: "r-help@r-project.org" <r-help@r-project.org>
>> Subject: Re: [R] [ggplot2] Wind rose orientation
>> Hi Hadley,
>>
>> That solved a lot of problems.  Thanks!
>>
>> Do you get a vertically oriented bar?  Here I get 15 bars with a  
>> space where
>> the north bar, the 16th bar, should be.
>>
>> All the best,
>> Tom
>>
>> On Dec 3, 2009, at 8:16 PM, hadley wickham wrote:
>>
>> Hi Thomas,
>>
>> Ok, the key thing that you were missing was:
>>
>> scale_x_continuous(limits = c(0, 360))
>>
>> Since you don't have any data at 0, and because ggplot2 doesn't know
>>
>> that your variable had intrinsic meaning as a degree, it was starting
>>
>> zero degrees at 22.5.
>>
>> A few other tweaks below:
>>
>> wind.data$wind <- factor(wind.data$wind,
>>
>> c("calm", "< 3", "4 - 12", "13 - 24", "> 25"))
>>
>> ggplot(wind.data, aes(x = degree, y = time, fill = wind)) +
>>
>> xlab(NULL) + ylab(NULL) +
>>
>> geom_bar(stat = "identity", aes(width = 22.5)) +
>>
>> scale_x_continuous(limits = c(0, 360), breaks = c(0, 90, 180, 270)) +
>>
>> coord_polar() +
>>
>> scale_fill_brewer(pal = "Blues")
>>
>> Regards,
>>
>> Hadley
>>
>> On Fri, Dec 4, 2009 at 12:02 AM, Thomas S. Dye <tsd@tsdye.com> wrote:
>>
>> 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
>>
>>
>>
>> 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@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@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/
>>
>>
>>
>>
>>
>>
>> --
>>
>> http://had.co.nz/
>>
>> ______________________________________________
>> R-help@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.
>>
>>
>>
>> Thomas S. Dye, Ph.D.
>>
>> T. S. Dye & Colleagues, Archaeologists, Inc.
>>
>> Phone: (808) 529-0866 Fax: (808) 529-0884
>>
>> http://www.tsdye.com
>>
>>
>
>
>
> -- 
> http://had.co.nz/



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]]


