r - 如何使用绘图功能从矩阵中绘制多列
问题描述
我正在尝试使用 plot 绘制我的矩阵列,但看起来我在某处犯了错误。我在网上找到了示例代码,所以我不完全确定如何解决它。
d <- seq(from = 0.3, to = 0.5, by = 0.01)
nd <- length(d)
p <- seq(from = 0.6, to = 0.8, by = 0.1)
np <- length(p)
samplesizes <- data.frame(matrix(data=0, nrow=nd, ncol=np))
names(samplesizes) <- p
rownames(samplesizes) <- d
for (i in 1:np){
for (j in 1:nd){
result <- power.t.test(n=NULL, d = d[j], sig.level = .05,
power = p[i], alternative = "one.sided")
samplesizes[j,i] <- result$n
}
}
#-----------------------------------------------------
xrange <- range(d)
yrange <- round(range(samplesizes))
colors <- rainbow(length(p))
plot(samplesizes, xrange, yrange, type="n", xlab="Sample size (n)",
ylab="Effect Size (d)", las = 1)
for (i in 1:np){
lines(s, effectsizes[,i], type="l", lwd=2, col=colors[i])
}
legend("topright", title="Power", as.character(p), fill=colors)
我正在尝试获得与此示例图类似的东西,但 Y 轴上的样本和 X 轴上的效果大小。
解决方案
也许你正在寻找这个 -
d <- seq(from = 0.3, to = 0.5, by = 0.01)
nd <- length(d)
p <- seq(from = 0.6, to = 0.8, by = 0.1)
np <- length(p)
samplesizes <- data.frame(matrix(data=0, nrow=nd, ncol=np))
names(samplesizes) <- p
rownames(samplesizes) <- d
for (i in 1:np){
for (j in 1:nd){
result <- power.t.test(n=NULL, d = d[j], sig.level = .05,
power = p[i], alternative = "one.sided")
samplesizes[j,i] <- result$n
}
}
xrange <- range(d)
yrange <- round(range(samplesizes))
colors <- rainbow(length(p))
plot(xrange, yrange, type="n", xlab="Sample size (n)",
ylab="Effect Size (d)", las = 1)
for (i in 1:np){
lines(d, samplesizes[,i], type="l", lwd=2, col=colors[i])
}
legend("topright", title="Power", as.character(p), fill=colors)
推荐阅读
- ios - 我需要帮助将 swift 3 写入 swift 4
- python - Python/Pandas - 调用特定列的数据框目录
- python - 使用python将多个tiff图像转换为pdf
- ruby-on-rails - 这个 rspec expect 块在做什么?
- python-3.x - 两个数字相加问题(链表) - Python - Leetcode - AttributeError
- r - 将 enquo 与 infer 包一起使用
- javascript - 如何使用 Javascript 从服务器获取特定的 JSON 数据?
- prolog - Prolog中没有统一的匹配模式
- sql - 如何使用 UNION 运算符合并星期几?
- database - SpringBoot, JPA, JPARepository findAll() 返回空值