r - Multiple regression line of best fit
问题描述
I am trying to fit a line using ggplot2 to a multiple regression but dont know the best way to do this. What I am looking at is the effect of logging on the mass of different trophic groups of beetles. I have 5 different trophic groups, and I don't know if the graph will look too messy. So far I have tried to fit it just on the 'carnivores' group with the following code:
ggplot(data=dat[dat$TL1=="Carnivorous"], aes(x= agb, y=Mass)) +
geom_point(color="blue") +
geom_smooth(method = "lm", se= FALSE)
but it doesn't seem to be working.
解决方案
Try something like this:
ggplot(dat, aes(agb, Mass) +
geom_point(aes(color = TL1)) +
geom_smooth(method = "lm", aes(group = TL1, color = TL1))