Predict Selection: Carat:0.23 ; cut:Ideal ; Color:E ; Clarity:SI2
# Select columns to be used in the analysis
diam <- diamonds[,c(1:4,7)]
# build linear regression model
fit <- lm( price~carat, diam)
# predicts the price
pred <- predict(fit, newdata = data.frame(carat = 0.23,
cut = 'Ideal',
color = 'E',
clarity = 'SI2'))
# Draw the plot using ggplot2
Demo_plot <- ggplot(data=diam, aes(x=carat, y = price))+
geom_point(aes(color = cut), alpha = 0.4)+
geom_smooth(method = "lm")+
geom_vline(xintercept = 0.23, color = "blue")+
geom_hline(yintercept = pred, color = "blue")