I am working on a rose diagram using gghistogram. Here is what I have so far:
Data:
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))
I'm looking to turn the diagram so 0/360 is at the top (North). Additionally, is there a way to relabel the "0/360" as simply "0"?
Current code:
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)
CodePudding user response:
If you remove the start
argument for coord_polar()
it start with 0/360 at the top. Labelling that starting point with just 0 can be achieved by omitting the last break.
# 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).