gpt4 book ai didi

r - 带有ggplot2的ACF图:设置geom_bar的宽度

转载 作者:行者123 更新时间:2023-12-03 13:50:28 24 4
gpt4 key购买 nike

使用acf,我们可以在基础ACF plot图中创建R

x <- lh
acf(x)




以下代码可用于获取 ACF plot中的 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






如何获得线条而不是线条,或者如何设置线条宽度以使其看起来像线条?谢谢

最佳答案

您最好通过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

关于r - 带有ggplot2的ACF图:设置geom_bar的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17788859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com