0
# Superimpose the decision boundary on the scatterplot of GPA vs. GMAT
ggplot(train, aes(x = GPA, y = GMAT, color = Group)) + 
  geom_point() +
  ggtitle("Scatterplot of GPA vs. GMAT by Group with LDA Decision Boundary") +
  geom_contour(aes(z = predict(lda.fit, data.frame(GPA, GMAT))$class),
               bins = 2, alpha = 0.5)
Error in Summary.factor(c(1L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : 
  ‘range’ not meaningful for factors
Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
  • You haven't shown us a [mcve], but `predict(lda.fit, ...)` returns a factor variable. You can't use that as the z variable for a contour plot. What are you trying to do? Plot decision boundaries? https://stackoverflow.com/questions/24260576/plot-decision-boundaries-with-ggplot2 – Ben Bolker Mar 07 '23 at 22:22
  • yes i am trying to plot decision boundaries – Remonda Hanna Mar 07 '23 at 23:05
  • lda.fit <- lda(Group ~ GPA + GMAT, data = train) – Remonda Hanna Mar 07 '23 at 23:06
  • train <- admission[admission$Group != "border", ] – Remonda Hanna Mar 07 '23 at 23:06
  • Right, this is not a **reproducible** example - we need to know where "admission" comes from. You could probably use the example from `?predict.lda` as the starting point of a reproducible example ... (Does looking at the question/answer I linked above help you solve your problem?) – Ben Bolker Mar 07 '23 at 23:36

0 Answers0