-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Hi there,
I think there may need to be an adjustment to the way the season dimension is handled in ggplotFL. In my example, I have 12 months in the season dimension. I believe season gets originally treated as a factor, and then converted to numeric. This seems to mess up the month order in my case (e.g. "1", "10", "11", "12", "2", "3", "4", "5", "6", "7", "8", "9").
Below is a fix that re-orders the levels based on their sequence in the dimnames of the FLStock object.
direct plot with ggplotFL:
plot(stk@stock.n)
adjusted version with ggplot2:
DIMNAMES <- dimnames(stk@stock.n)
df <- as.data.frame(stk@stock.n)
df$season <- factor(df$season, levels = DIMNAMES$season)
df$date <- as.Date(paste(df$year,
as.numeric(df$season), "01", sep = "-"),
format = "%Y-%m-%d")
p <- ggplot2::ggplot(data = df,
aes(x = date, y = data, group = age)) +
facet_wrap(~ age, ncol = 1, scales = "free_y",
drop=TRUE, strip.position = "right") +
scale_y_continuous(limits = c(0,NA)) +
geom_line()
print(p)

