I have data on frequency of damaged and healthy forest in 20-degree aspect classes (slope direction). The midpoints of the classes, which I want to use for plotting, start at 10 deg and go up to 350. I want to simply close the line between 350 and 10, but copying the 10-deg line to after the 350 just gets ignored. I've read some questions that seem similar but the answers don't apply to this case. How to close the line between 350 and 10 degrees?
Data:
DATA <- read.table( text=
"aspect relfreq
10 0.067074037
30 0.033252807
50 0.027284354
70 0.013642177
90 0.009236891
110 0.038652835
130 0.036379139
150 0.069489839
170 0.099758420
190 0.116953247
210 0.084837289
230 0.047037090
250 0.051300270
270 0.049168680
290 0.066931931
310 0.071337218
330 0.069774051
350 0.047889726
10 0.067074037", header=TRUE )
Code:
p <- ggplot( DATA, aes( x=aspect, y=relfreq) ) +
geom_line( color="red", size=4 ) +
coord_polar( ) +
scale_x_continuous( limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 360-1, by = 90)) +
ylim( 0, max( DATA$relfreq ) ) +
xlab( NULL ) + ylab( NULL ) +
theme_bw() +
theme(panel.border = element_blank(),
legend.key = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text( size=15 ))
You could get the value that is midway between the values at 350 and 10 degrees and plot it at 0 and 360 degrees. You'll want to remove the repeated value at 10 degrees first to do this accurately:
# Remove repeated observation at 10 degrees
DATA <- head(DATA, -1)
DATA |>
rbind(c(0, mean(DATA$relfreq[DATA$aspect %in% c(10, 350)]))) |>
rbind(c(360, mean(DATA$relfreq[DATA$aspect %in% c(10, 350)]))) |>
ggplot(aes(aspect, relfreq)) +
geom_line(color = "red", size = 4, lineend = "round") +
coord_polar() +
scale_x_continuous(NULL, limits = c(0, 360), expand = c(0, 0),
breaks = seq(0, 360 - 1, by = 90)) +
scale_y_continuous(NULL, limits = c(0, max(DATA$relfreq))) +
theme_bw() +
theme(panel.border = element_blank(),
legend.key = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 15))