I have a scatterplot and the underlying regression model. I would like to give a nice example on another datapoint (assume not included in the estimation sample), i.e. it's actual versus predicted value. I have everything ready but for the labels (thinking about geom_text or geom_label, nothing working so far):
data(mtcars)
model <- lm(mpg ~ wt, data=mtcars)
mycar <- data.frame(wt=c(2.5))
predict(model, mycar)
model <- lm(Coupon ~ Total, data=df)
mycar <- data.frame(Total=c(79037022, 83100656, 104299800))
predict(model, new.df)
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point() +
geom_smooth(method="lm", se=FALSE) +
geom_point(aes(x=2.5,y=23.92395), # red is the prediction for my car
color='red',
size=3, show.legend = TRUE) +
geom_point(aes(x=2.5,y=28), # green is the actual mpg of my car
color='green',
size=3)
I am flexible at the exact implementation:
- Text may be in same colour as datapoint (without line or arrow)
- Text in black colour with line or arrow (would require a box background since in real data the datacloud is almost black everywhere)
- There could be a legend which maps the colour of manual added points to text label (alhtough I fancy the label next to the data points).
- ...
I am looking for something easy to implement and visually appealing. Thank you




