0

我正在使用 gghistogram 绘制玫瑰图。这是我到目前为止所拥有的: 在此处输入图像描述

数据:

structure(list(Dataset = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),.Label = "Outcrop 9", class = "factor"), Orientation = c(205L, 124L, 312L, 212L,196L, 203L, 212L, 155L, 193L, 160L)), class = "data.frame", row.names = c(NA, -10L))

我正在寻找转动图表,因此 0/360 位于顶部(北)。此外,有没有办法将“0/360”重新标记为“0”?

当前代码:

library(ggplot2)
library(scales)
colours<-c("#D52B1E","pink","black")
plot<-ggplot() + 
  geom_line(aes(x = c(0, 360), y = c(4, 4)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(8, 8)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(12, 12)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(16, 16)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(20, 20)), colour = "gray75") +
  geom_vline(aes(xintercept = 0:12 * 30), colour = "gray75") +
  geom_histogram(data = df, aes(x=Orientation, fill=factor(Dataset)), 
                 position = "stack", colour = "black", binwidth = 20,
                 boundary = 0) +theme_bw() + scale_fill_manual(values=colours)+
  coord_polar(start = 3 * pi / 2) + 
  scale_x_continuous(limits = c(0, 360), breaks = 0:12 * 30) +
  scale_y_continuous(limits = c(0, 4)) + theme(panel.border=element_blank(), axis.title.y = element_blank(), axis.title.x = element_blank(),legend.position="none")```

(Please ignore the fact that I have added extra colours, I will be adding in two more datasets later)
4

1 回答 1

1

如果您删除它的start参数,coord_polar()则从顶部的 0/360 开始。可以通过省略最后一个中断来仅用 0 标记该起点。

# df <- structure(...) # omitted for brevity

library(ggplot2)
library(scales)
colours<-c("#D52B1E","pink","black")

ggplot() + 
  geom_line(aes(x = c(0, 360), y = c(4, 4)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(8, 8)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(12, 12)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(16, 16)), colour = "gray75") +
  geom_line(aes(x = c(0, 360), y = c(20, 20)), colour = "gray75") +
  geom_vline(aes(xintercept = 0:12 * 30), colour = "gray75") +
  geom_histogram(data = df, aes(x=Orientation, fill=factor(Dataset)), 
                 position = "stack", colour = "black", binwidth = 20,
                 boundary = 0) +theme_bw() + scale_fill_manual(values=colours)+
  coord_polar() + 
  scale_x_continuous(limits = c(0, 360), breaks = 0:11 * 30) +
  scale_y_continuous(limits = c(0, 4)) + 
  theme(panel.border=element_blank(), 
        axis.title.y = element_blank(), 
        axis.title.x = element_blank(),
        legend.position="none")
#> Warning: Removed 2 row(s) containing missing values (geom_path).

#> Warning: Removed 2 row(s) containing missing values (geom_path).

#> Warning: Removed 2 row(s) containing missing values (geom_path).

#> Warning: Removed 2 row(s) containing missing values (geom_path).

于 2021-10-07T21:00:52.093 回答