Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the "zero" oritentation in ggplot2 of R?

Tags:

r

ggplot2

In my code, read the data to draw the polar plot image. But the "0 /360" is in the top. How can I rotate it to the right hand by 90 degrees?

ggplot(polar, aes(x=angle, y=distance )) + coord_polar(start=0) + geom_point() +
  scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0), lim=c(0, 360))+
  scale_area()

The full procedure and resulting graphic is described here: http://keveting.blogspot.tw/2012/08/r-ggplot2-code.html

The documentation for coord_polar:

start : offset from 12 o'clock in radians direction: 1, clockwise ; -1, anticlockwise

so I tried

ggplot(polar, aes(x=angle, y=distance)) + 
  coord_polar(***start = 90, direction = -1***) +
  geom_point() + scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0),
  lim=c(0, 360)) + scale_area()

But it still doesn't rotate the plot the way I want it to the right by 90 degrees.

like image 654
user1623267 Avatar asked Aug 24 '12 17:08

user1623267


1 Answers

I think this is what you're looking for:

ggplot(polar, aes(x=angle, y=distance)) + 
  coord_polar(start = 1.57, direction=1) + geom_point() + 
  scale_x_continuous(breaks=seq(0, 360, by=30), expand=c(0,0), lim=c(0, 360)) +
  scale_area()

enter image description here

As the link to the coord_polar documentation says, the start is the offset in radians (not degrees) and you want to rotate it clockwise (so direction=1).

like image 192
smillig Avatar answered Sep 23 '22 04:09

smillig