ACF Plot with ggplot2: Setting width of geom_bar

前端 未结 4 1018
时光说笑
时光说笑 2021-02-18 23:25

With acf we can make ACF plot in base R graph.

x <- lh
acf(x)

4条回答
  •  逝去的感伤
    2021-02-19 00:19

    You're probably better off plotting with line segments via geom_segment()

    library(ggplot2)
    
    set.seed(123)
    x <- arima.sim(n = 200, model = list(ar = 0.6))
    
    bacf <- acf(x, plot = FALSE)
    bacfdf <- with(bacf, data.frame(lag, acf))
    
    q <- ggplot(data = bacfdf, mapping = aes(x = lag, y = acf)) +
           geom_hline(aes(yintercept = 0)) +
           geom_segment(mapping = aes(xend = lag, yend = 0))
    q
    

    enter image description here

提交回复
热议问题