转动圆形图
Turning circular gghistogram
我正在使用 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)
如果删除 coord_polar()
的 start
参数,它会从顶部的 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).
我正在使用 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)
如果删除 coord_polar()
的 start
参数,它会从顶部的 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).