gpt4 book ai didi

使用 R 中的 Hmisc::xYplot 旋转网格以绘制水平误差条

转载 作者:行者123 更新时间:2023-12-03 00:01:50 26 4
gpt4 key购买 nike

我正在使用 xYplot 绘制带有误差线的回归结果。但是,xYplot 仅绘制水平误差线,我需要垂直误差线。四处寻找解决方案,我发现 this thread 有人问了大致相同的问题。经过一些消息后,提出问题的用户说“我刚刚发现使用 xYplot (Hmisc) 并旋转网格视口(viewport)(和标签等)给了我正是我所需要的”。

所以我研究了如何旋转网格,发现使用网格库和pushviewport等可以旋转网格。但是,我的代码不起作用。这是我到目前为止所做的尝试:

estimate=structure(list(coefi = c(-5.08608456607495, -4.17906898422091, 
-2.85696514398422, -3.06968196245069, -2.73660002514793, -1.0017403629931,
-1.66291850690335, 0.431265159072978, -0.472895611533531, 0.845421348865878,
-0.437434919008876, 0.269041451577909, -0.233066564595661, 0.0137190330621302,
-2.94808159763314, 1.9166875739645), lower = c(-8.1895, -6.8485,
-5.214125, -5.532875, -5.106625, -3.271625, -3.97375, -0.09773,
-1.340625, 0.415125, -0.86615, 0.02665125, -0.5861, -2.079, -5.626625,
0.8115125), upper = c(-2.11475, -1.611125, -0.5602375, -0.7309625,
-0.3721375, 1.259875, 0.7167875, 0.9672875, 0.39035, 1.30025,
-0.05634125, 0.5115, 0.07237875, 2.14275, -0.3653, 4.202625),
x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16)), .Names = c("coefi", "lower", "upper", "x"), row.names = c("alpha.1.",
"alpha.2.", "alpha.3.", "alpha.4.", "alpha.5.", "alpha.6.", "alpha.7.",
"b.income", "b.democracy", "b.ginete", "b.educ", "b.patent",
"b.fdi", "b.0", "mu.alpha", "sigma.alpha"), class = "data.frame")

legenda=c(as.character(seq(1970,2000,5)),"PIB_pc", "democ", "legis", "educ", "patent", "FDI", "b.0", "mu.ano", "var.ano" )

grid.newpage()
pushViewport(viewport(angle = 90, name = "VP"))
upViewport()
xYplot(Cbind(coefi,lower, upper) ~x, data=estimate, , varwidth = TRUE, ylab="Betas",
xlab="Inclinação das Covariáveis com respectivos 95% intervalos de credibilidade \n N=409",
ylim=with(estimate,c(min(lower)-.5, max(upper)+.5)), scales=list(cex=1.2, x = list(at=seq(1,16, by=1), labels = legenda)) ,abline=c(list(h=0), lty="dotted", col= "grey69"), xlab.top="Adesão ao Tratado de Cooperação de Patentes, 1970-2000", draw.in = "VP")

如果有任何帮助,我将不胜感激。

更新:有评论指出代码是正确的。所以我想知道我是否无法传达我想要的内容或者它是否是一个错误...所以我现在会发布我的代码输出的图像,你告诉我你的计算机中的代码是否给出相同的输出或另一个输出:

enter image description here

最佳答案

您必须直接在网格对象上调用print(网格文档中提到RShowDoc("grid", package="grid") - “将网格添加到网格”):

require(grid)
grid.newpage()
pushViewport(viewport(angle = 90, name = "VP"))

print(
xYplot(Cbind(coefi,lower, upper)~x, data=estimate, , varwidth = TRUE,
ylab="Betas", xlab="Inclinaçao das Covariáveis com respectivos 95% intervalos de credibilidade \n N=409",
ylim=with(estimate,c(min(lower)-.5, max(upper)+.5)),
scales=list(cex=1.2, x = list(at=seq(1,16,by=1), labels = legenda)),
abline=c(list(h=0), lty="dotted", col= "grey69"),
xlab.top="Adesao ao Tratado de Cooperaçao de Patentes, 1970-2000",
draw.in = "VP"
),
newpage=FALSE
)

Rotated xYplot

关于使用 R 中的 Hmisc::xYplot 旋转网格以绘制水平误差条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6392266/

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