使用面板数据,我在人口变量变量age上回归了144列(时间步长)
我将统计信息保存在名为Age的数据框中
dput(head(Age, 10))
structure(list(term = c("(Intercept)", "act1_1", "(Intercept)",
"act1_2", "(Intercept)", "act1_3", "(Intercept)", "act1_4", "(Intercept)",
"act1_5"), estimate = c(44.3846208128138, -0.000384107652327793,
44.3174018132914, -5.98548832764511e-05, 44.2450887508948, 0.000196982881599239,
44.2072004527491, 0.000308764204242224, 44.181318653263, 0.000390867379854134
), std.error = c(0.168699503373036, 0.000204411891544783, 0.168567124457874,
0.000184836499264514, 0.16808328410892, 0.000136569949465428,
0.168158343129598, 0.000131172551491056, 0.168235711394923, 0.000132127095441471
), statistic = c(263.098704651599, -1.8790866295743, 262.906554026,
-0.32382610314857, 263.233128656764, 1.44235889645037, 262.890318910189,
2.35387816073149, 262.615578386625, 2.95826816254565), p.value = c(0,
0.0602502440977185, 0, 0.746073789321371, 0, 0.14922009840405,
0, 0.0185903375815117, 0, 0.00309810897731306)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
如何以有意义的方式绘制p值(考虑到act1_1时间步长)?
答案 0 :(得分:2)
library(ggplot2)
library(dplyr)
df <- df %>%
dplyr::mutate(term = c("Interecpt1", "act1_1",
"Intercept2", "act1_2",
"Intercept3", "act1_3",
"Intercept4", "act1_4",
"Intercept5", "act1_5"),
signif = ifelse(p.value > 0.05 , 1, 0),
signif = as.factor(signif)) # alpha = 5%
ggplot2::ggplot(df) +
geom_point(aes(x = term, y = p.value, col = signif), size = 2, show.legend = F) +
geom_hline(yintercept = 0.05, linetype = 2, col = "red") +
coord_flip() +
scale_color_manual(values = c("darkblue", "darkred")) +
theme_bw()
答案 1 :(得分:1)
假设x轴是日期列,则可以使用函数scale_x_date()
并设置需要缩放的值,x轴看起来会好很多。
示例语句如下所示。
p1 <- p1 + scale_x_date(date_breaks = "1 week")