我正在使用Visreg可视化一个带有相互作用项的负二项式一般线性模型。我遇到的问题是,当使用overlay=TRUE时,说明哪些行对应于哪个级别的"by“变量的图例被放在图形的顶部,直接放在标题上。我尝试了一种奇怪的解决方法,在标题的末尾添加回车符,但我发现当我将图表大小调整为更大时,图例会被推高,直到完全隐藏。
我的代码:
visreg(fit, "med.income.2010.scale", by="hs.edu.2010", overlay=TRUE,
partial=FALSE, scale="response",
main="Inspection Rates by Income and Education",
ylab="Predicted Routine Inspections",
xlab="Median Household Income (thousands)",
strip.names=c("10th Percentile", "50th Percentile", "90th Percentile"),
legend=TRUE)有什么想法吗?
发布于 2017-08-10 02:23:50
我最终找到了一种解决方法,将visreg输出分配给一个对象(v=visreg(fit,等等))使用r的基本打印函数( plot (v等))绘制它,然后使用它后面的图例函数。
我的完整代码是
'v= visreg(m1.routine.inspect, "med.income.2010.scale", by="hs.edu.2010", overlay=TRUE, partial=FALSE, scale="response", legend=FALSE)'
plot(v, overlay=TRUE, legend=FALSE,
main="Inspection Rates by Income and Education,\nInteraction Term Excluded",
ylab="Predicted Routine Inspections per well",
xlab="Median Household Income (thousands)",
font.lab=1,
yaxs="i",
ylim=c(0,1.1),
cex.lab=1)
legend.enhanced("bottomright",
c("10th Percentile", "50th Percentile", "90th Percentile"),
lty=1,
lwd=3,
col=c("red", "forestgreen", "royalblue"),
bty="n",
title=expression(underline("HS Grad Rate")),
horiz=FALSE,
y.intersp=.5,
x.intersp=.5,
title.adj=c(.5,0),
title.col="black",
seg.len =1,
cex=1,
yjust=.3,
text.font = NULL,
inset = .05
)通常情况下,您只需使用图例(...),但用户发布了一个修改后的函数,允许更好地调整图例标题。
https://stackoverflow.com/questions/45553816
复制相似问题