r - How to put the actual data points on the contour plot with ggplot? -
the code below produces contour plot using ggplot. xgrid <- seq(min(mtcars$wt), max(mtcars$wt), 0.3) ygrid <- seq(min(mtcars$hp), max(mtcars$hp), 0.3) data.fit <- expand.grid(wt = xgrid, hp = ygrid) data.loess <- loess(qsec ~ wt * hp, data = mtcars) mtrx3d <- predict(data.loess, newdata = data.fit) mtrx3d[1:4, 1:4] require(reshape) mtrx.melt <- melt(mtrx3d, id.vars = c("wt", "hp"), measure.vars = "qsec") names(mtrx.melt) <- c("wt", "hp", "qsec") require(stringr) mtrx.melt$wt <- as.numeric(str_sub(mtrx.melt$wt, str_locate(mtrx.melt$wt, "=")[1,1] + 1)) mtrx.melt$hp <- as.numeric(str_sub(mtrx.melt$hp, str_locate(mtrx.melt$hp, "=")[1,1] + 1)) ggplot(mtrx.melt, aes(x = wt, y = hp, z = qsec)) + stat_contour() i wonder how show acutal data points contour lines. have tried ggplot(mtrx.melt, aes(x = wt, y = hp, z = qsec)) + stat_contour() + geom_point(mtrx.melt, ae...