0

I'm generating a polar chart in R with plotrix. The angle is record hearding and the length is taken from the record timestamp. The dates are parsed with lubridate parse_date_time

polar.plot(
    as.numeric(df$datetime), 
    df$heading, 
    rp.type="p", 
    start=90, 
    clockwise=TRUE, 
    show.grid.labels=FALSE
)

The issue I have is that polygon links the first and last points. I also have a few gaps in the data. These two circumstances lead to lines of the polygon crossing over the middle of the chart. Ideally, I wouldn't link the first and last points and I'd break the connecting lines whenever there's a significant gap in the time-series.

I'm already calculating the delta between each record, so it is easy enough to identify where I want those gaps to occur.

I'm not tied to plotrix if there is another way to achieve these goals.

Thanks for any help.

fracai
  • 307
  • 2
  • 14

1 Answers1

0

Figures... a few more minutes and I mostly have a solution.

First, I'm getting a decent polar chart with ggplot2. I'm not sure how I didn't find that earlier.

ggplot2 polar plot arrows:

ggplot(df, aes(heading, datetime)) + coord_polar() + geom_path()

And I think I should be able to get the gaps either by inserting "NA" values or generating groups. Line break when no data in ggplot2:

idx <- c(1, diff(df$datetime))
i2 <- c(1,which(idx != 1), nrow(df)+1)
df$grp <- rep(1:length(diff(i2)), diff(i2))
ggplot(df, aes(heading, datetime)) + coord_polar() + geom_path(group=grp)

I'm not sure how I didn't find plotting polar with ggplot2.

Though, ggplot2 isn't picking the shortest path to connect points (it loops all the way around the chart to connect 10 to 350 rather than crossing 0).

Edit: And that can be solved with coord_map() ggplot2: How to link correctly track points around polar projection map?

Edit 2: Nevermind, coord_map isn't meant for this

Community
  • 1
  • 1
fracai
  • 307
  • 2
  • 14