I just wondering is it possible to add legend, when we got two diffrent sets of points.
samochodziki %>%
mutate(dopasowane = model_classic$fitted.values) %>%
arrange(lp100k) %>%
mutate(index = 1:nrow(samochodziki)) %>%
ggplot(aes(x = index)) +
geom_point(aes(y = lp100k), color = "red") +
geom_point(aes(y = dopasowane), color = "blue")
Data on which I working:
structure(list(lp100k = c(9.8006076285327, 11.2006944326088,
7.4671296217392, 12.1244630456075, 13.0674768380436, 8.11084769257879
), cylinders = c(4L, 6L, 4L, 6L, 6L, 4L), displacement = c(1474.8354,
3277.412, 1458.44834, 3801.79792, 3687.0885, 1114.32008), horsepower = c(75L,
85L, 71L, 90L, 105L, 49L), weight = c(956.17271596, 1173.44346119,
902.6488163, 1456.0315077, 1415.66178677, 846.85695479), acceleration = c(15.5,
16, 14.9, 17.2, 16.5, 19.5), year = c(74L, 70L, 78L, 78L, 73L,
73L), origin = c(2L, 1L, 2L, 1L, 1L, 2L), name = c("fiat 128",
"ford maverick", "volkswagen scirocco", "amc concord", "plymouth valiant",
"fiat 128")), .Names = c("lp100k", "cylinders", "displacement",
"horsepower", "weight", "acceleration", "year", "origin", "name"
), row.names = c(NA, 6L), class = c("tbl_df", "tbl", "data.frame"
))
Model_classic shape
Call:
lm(formula = lp100k ~ horsepower + weight + year, data = samochodziki)
Residuals:
Min 1Q Median 3Q Max
-3.3229 -0.7818 -0.0626 0.6344 6.3843
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 22.8668314 1.8503686 12.358 < 2e-16 ***
horsepower 0.0151390 0.0042094 3.596 0.000375 ***
weight 0.0068079 0.0003937 17.294 < 2e-16 ***
year -0.2950063 0.0230468 -12.800 < 2e-16 ***
So I want to add legend that for red points got "real", and for blue points "fitted".