我正在使用 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)
uj5u.com熱心網友回復:
如果您洗掉它的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).

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/315905.html
