Skip to content

plotting object with season dimension = 12 #13

@marchtaylor

Description

@marchtaylor

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)

ggplotfl

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)

ggplot2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions