简体   繁体   中英

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. Right now, it uses the observation numbers. I'd rather it use a column named "community" in df.ca for the label names.

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.

Here's my data in RDS format. The dataframe is 77x202 so I haven't copied it here.

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?
  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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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