Reputation: 1499
I have created a graph with the following code and data:
ggplot(data.frame, aes(x=Score, y=Year, col=Position)) +
geom_smooth(method="lm", se=FALSE).
Year Position Score
2010 QB 16.5
2011 QB 15.4
2012 QB 16.1
2013 QB 14.3
2014 QB 13.8
2010 RB 14.2
2011 RB 13.9
2012 RB 13.9
2013 RB 11.8
2014 RB 11.6
2010 WR 11.4
2011 WR 12.4
2012 WR 10.4
2013 WR 8.8
2014 WR 9.7
My goal is to do a similar graph with the data below, except with a logistic regression since the Y-value (Score1) is binary. I tried changing the method="lm"
to method="Binominal"
but that hasn't worked. Can anyone help? I'd prefer that it's done in ggplot so that the graphs look as similar in composition as possible.
Score1 Position Score2
0 QB 16.5
0 QB 15.4
1 QB 16.1
0 QB 14.3
1 QB 13.8
1 RB 14.2
1 RB 13.9
1 RB 13.9
0 RB 11.8
0 RB 11.6
1 WR 11.4
1 WR 12.4
0 WR 10.4
1 WR 8.8
1 WR 9.7
Upvotes: 0
Views: 888
Reputation: 1383
Use stat_smooth
instead of geom_smooth
, like this:
ggplot(data.frame, aes(x=Score, y=Year, col=Position)) + stat_smooth(method="glm", family="binomial",se=fALSE)
EDIT: You might need qplot
, there is an example for logistic regression at the end of the following link https://www.rdocumentation.org/packages/ggplot2/versions/0.9.0/topics/stat_smooth
Upvotes: 2
Reputation: 911
The correct way of doing this would be
ggplot(data.frame, aes(x=Score2, y=Score1, col=Position)) +
+ geom_smooth(method="glm",method.args = list(family = "binomial"), se=FALSE)
however, Score1 should be 0 or 1, so you'd have to transform your classes and potentially make multiple plots.
Upvotes: 4