简体   繁体   English

R:ggfortify:指定用于图中标签的列

[英]R: ggfortify: specify column to use for labels in plots

I'm using ggfortify to draw some diagnostic plots for my lm and glm objects, but I can't figure out how to specify the labels to use. 我正在使用ggfortify为我的lmglm对象绘制一些诊断图,但我无法弄清楚如何指定要使用的标签。 Right now, it uses the observation numbers. 现在,它使用观察数字。 I'd rather it use a column named "community" in df.ca for the label names. 我宁愿在df.ca使用名为“community”的df.ca作为标签名称。

The GLM example here shows text like I'm looking to do, and I can't see any different specifications under label.label or anything similar. 这里GLM示例显示了我正在寻找的文本,我在label.label或类似的东西下看不到任何不同的规范。

Here's my data in RDS format. 这是我的RDS格式的数据。 The dataframe is 77x202 so I haven't copied it here. 数据帧是77x202所以我没有在这里复制它。

Here's the code that specifies the model and then plots: 这是指定模型的代码,然后绘制:

summary(m.ca.ppc <- lm(ppc ~ medinc + hisp + black + asian, data = df.ca))
autoplot(m.ca.ppc, which = 1:6, ncol = 3, label.size = 3)

Which produces 哪个产生 由ggfortify制作的情节

My questions are: 我的问题是:

  1. How do I get the community names instead of the observation numbers (eg, 39, 36 in the Residuals vs Fitted plot) to appear? 如何显示社区名称而不是观察数字(例如,残差与拟合图中的39,36)?
  2. How do I have the label not overlap the dot so I can read it easily? 如何让标签不与点重叠,以便我可以轻松阅读?

[edited to clarify after questions in the comments] [编辑后在评论中提出澄清]

您必须激活文本标签,指向相关列,然后关闭点。

autoplot(m.ca.ppc, data = df.ca, label.size = 3, label=TRUE, label.label="community", shape=FALSE, which=1:6, ncol=3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM