我想用power
绘制F-test
的{{1}},并使用图表输出绘制MWE:
ggplot2
我想知道如何让它更透明。不同地区不是很清楚。任何建议将受到高度赞赏。感谢
答案 0 :(得分:2)
通过alpha
图形参数控制透明度。只需将此值设置为较低的图层值即可。现在你已经将它设置为1/3,尝试将其设置为1/6
library(ggplot2)
df1 <- 3
df2 <- 8
Alpha <- 0.05
df <- data.frame(X = seq(from = 0, to = 10, length = 500))
p <- ggplot(data=df, mapping=aes(x = X, y = df(x = X, df1 = df1, df2 = df2, ncp=0)))+
geom_area(color="black", fill="white")
p <- p + geom_area(aes(x=X, y=df(x = X, df1 = df1, df2 = df2, ncp=2)), color="blue", fill="blue", alpha = 1/6) ## this is the only line I've changed.
p <- p + scale_y_continuous(expand = c(0, 0)) + scale_x_continuous(breaks=seq(0, 10, 1))
p <- p + geom_area(data = subset(df, X > qf(p = 1-Alpha, df1 = df1, df2 = df2, ncp=0)), fill = "red")
p <- p + geom_area(data = subset(df, X > qf(p = 1-Alpha, df1 = df1, df2 = df2, ncp=0)),
aes(x=X, y=df(x = X, df1 = df1, df2 = df2, ncp=2)), fill = "green", alpha=1/3)
p
答案 1 :(得分:2)
在我看来,您应该首先定义要绘制的整个数据集,然后才开始绘图。这就是我要做的。
# load ggplot
require(ggplot2)
# define data
df1 <- 3
df2 <- 8
Alpha <- 0.05
X=seq(from = 0, to = 10, length = 500)
# Define the data outside ggplot
dd <- data.frame(x=c(X,X),
y=c(df(X, df1, df2, ncp=0), df(X, df1, df2, ncp=2)),
npc=factor(rep(c(0,2), each=length(X))),
quantile=c(X>qf(p = 1-Alpha, df1 = df1, df2 = df2, ncp=0),
# should this be qf(..., npc=0) or qf(..., npc=2)?
X>qf(p = 1-Alpha, df1 = df1, df2 = df2, ncp=2)))
# Plot
pp <- ggplot(data=dd, aes(x=x, ymin=0, ymax=y, fill=npc, color=npc, alpha=quantile))
pp <- pp + geom_ribbon()
# Play with different alpha-ranges until you are satisfied
pp + scale_alpha_discrete(range=c(.2, .5), guide="none")