1

I am plotting orientations ranging between 0 - 180 degrees of lineations in ggplot2 to make rose diagrams of orientation using:

ggplotrose <- function(data, title){
  dat <-data.frame(data)
  colnames(dat)[1] <- 'dat_x'
  ggplot(dat, aes(x=dat_x)) + 
  stat_bin(binwidth = 10, drop = FALSE, right = TRUE, col = "black", fill= "green") + 
  coord_polar() + ylab("Count") + ggtitle(title) + 
  scale_x_continuous("", limits = c(0, 360), breaks = seq(0, 360, 10))
}

I want to add in lines unrelated to my dataset showing the dominant orientations of regional faults (35 and 160 degrees) - i.e. add a red line trending to 35 degrees and one trending to 160 degrees on top of my existing rose diagram.

angles <- sample(0:180, 250, replace=TRUE)  #lineations with orientation between 0-180
fault <- 35  #fault orientation is 35 degrees

p <- ggplotrose(angles, 'sample data')  #create rose diagram of orientations
p + geom_segment(data=fault, aes(x=0, xend=cos(fault*(pi/180)), y=0, 
  yend=sin(fault*(pi/180))), colour="red")  #my attempt using geom_segment() which didn't work

I have tried using geom_line(), geom_segment(), geom_abline() but haven't been able to make any of them work.

Any suggestions would be much appreciated, thanks!

MadiN
  • 195
  • 4
  • 10
  • Please edit your question to make it [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by adding a minimal working example of your dataset. – tonytonov Aug 06 '14 at 07:13
  • You could try with `fault <- data.frame(fault=35)` (or alternatively omit `data=fault` from your `geom_segment` call). Also note that `p + geom_segment(aes(x=0, xend=cos(35*(pi/180)), y=0, yend=sin(35*(pi/180))), colour='red', lwd=2)` plots a segment, though I'm not sure the `*end` coordinates are supplied correctly. – jbaums Aug 07 '14 at 01:23
  • Thanks @jbaums I'm omitting the `data=fault` call from `geom_segment` as you suggested. I think the end coordinates were incorrect - the convention is to measure anticlockwise from x so the new code is `r <- 100` #I need to multiply by the circle radius here, I had assumed it was a unit circle so r=1 but the line only displays when I use a higher value (I use whatever my count is). `p + geom_segment(aes(x=0, xend=r*cos(90-(fault*(pi/180))), y=0, yend=r*sin(90-(fault*(pi/180)))), colour="red")` HOWEVER my line is now visible but curves around the plot rather than being straight... – MadiN Aug 08 '14 at 00:47

0 Answers0