带有ggplot2的ACF图:设置geom_bar的宽度 [英] ACF Plot with ggplot2: Setting width of geom_bar
本文介绍了带有ggplot2的ACF图:设置geom_bar的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用acf
,我们可以在基础R
图中创建ACF plot
.
With acf
we can make ACF plot
in base R
graph.
x <- lh
acf(x)
以下代码可用于获取ggplot2
中的ACF plot
.
The following code can be used to get the ACF plot
in ggplot2
.
conf.level <- 0.95
ciline <- qnorm((1 - conf.level)/2)/sqrt(length(x))
bacf <- acf(x, plot = FALSE)
bacfdf <- with(bacf, data.frame(lag, acf))
library(ggplot2)
q <- ggplot(data=bacfdf, mapping=aes(x=lag, y=acf)) +
geom_bar(stat = "identity", position = "identity")
q
问题
如何获取线条而不是线条,或者如何设置线条的宽度以使其看起来像线条?谢谢
How to get lines rather than bars or how to set the width of bars so that they look like lines? Thanks
推荐答案
最好通过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
这篇关于带有ggplot2的ACF图:设置geom_bar的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文