lll - 1 year ago 72

R Question

I have plot like the following using the

`ggplot2`

`ggplot(derivative_noHS, aes(x=Date, y=derv, linetype = Season)) +`

geom_line() +

scale_linetype_manual(values = c("dashed","solid","dashed","solid","dashed","solid","dashed",

"solid","dashed","solid","dashed","solid","dashed","solid"))+

facet_wrap(~Market, scales="free_y")+ geom_hline(aes(yintercept = positive.cut), derivative_noHS)+

geom_hline(aes(yintercept = zero),

derivative_noHS)+

geom_hline(aes(yintercept = negative.cut), derivative_noHS) + ggtitle("Figure 2 - Derivatives of Market Indices")+

scale_fill_discrete(breaks=c("2008sp","2008au","2009sp","2009au","2010sp","2010au","2011sp",

"2011au","2012sp","2012au","2013sp","2013au","2014sp","2014au"),

labels = c("2008sp","2008au","2009sp","2009au","2010sp","2010au","2011sp",

"2011au","2012sp","2012au","2013sp","2013au","2014sp","2014au")) +

ylab("Derivative Values")

Answer Source

You can try `ordered`

before calling `ggplot()`

```
derivative_noHS$Season <- ordered(derivative_noHS$Season, c("2008sp", "2008au", "2009sp",
"2009au", "2010sp", "2010au",
"2011sp", "2011au", "2012sp",
"2012au", "2013sp", "2013au",
"2014sp", "2014au"))
```