sinhrks / ggfortify

Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
Other
525 stars 65 forks source link

Cannot set alpha level for multivariate time-series using `autoplot()` #192

Closed xinbinhuang closed 6 years ago

xinbinhuang commented 6 years ago

Hi ggfortify developer,

I found it unable to set the alpha level for multivariate time-series. Here is the code.

library(forecast)
library(ggfortify)
library(tidyverse)

p <- sample(size = 100, 1:100)
q <- sample(size = 100, 1:100)
ts(cbind(p,q) ) %>% autoplot(alpha = 0.1)

Here I just make two series, but the number of series I am dealing with is 100. So the plot looks really bad. Is there any workaround to change the alpha level?

Thank your very much!

terrytangyuan commented 6 years ago

The issue is that since you loaded forecast package, you'll be using autoplot provided by forecast instead of by ggfortify. If you remove that library(forecast), you'll see the alpha level change.

If you really have to import forecast, you can force to use ggfortify's autoplot() using ggfortify:::autoplot.ts. Though it's not recommended but should be a workaround for you.

Note that you'll probably want facets = FALSE, e.g. ts(cbind(p,q)) %>% autoplot(alpha = 0.5, facets = FALSE) if you want to plot the lines in single axis. You can find the tutorial here.

xinbinhuang commented 6 years ago

@terrytangyuan Thank you very much! The information is really helpful. I use ggfortify:::autoplot.ts to solve my problem, because I still need to keep the forecast package

terrytangyuan commented 6 years ago

@xinbinhuang Great. Though ::: means it's an internal function but it should be stable enough to use.