R语言 极坐标图中350和10度之间的闭合线

wztqucjr  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(124)

我有20度坡向等级(坡向)中受损和健康森林频率的数据。类的中点,我想用来绘图,从10度开始,一直到350度。我想简单地关闭350和10之间的线,但复制10度线到350之后会被忽略。我读过一些问题,似乎相似,但答案不适用于这种情况。350度和10度之间的线怎么收?
数据:

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 )

代码:

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

ddrv8njm

ddrv8njm1#

您可以获取介于350度和10度值之间的值,并将其绘制在0度和360度处。您需要首先删除10度处的重复值,以准确地执行此操作:

# 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))

相关问题