使用R

时间:2017-08-07 18:49:13

标签: r graph model legend legend-properties

我正在使用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)

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我最终通过将visreg输出分配给对象来找到一种解决方法,(v = visreg(fit,etc ......)) 使用r的基本绘图功能(绘图(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
   )

通常你会使用图例(....),但是用户发布了一个修改过的功能,可以更好地调整图例标题。