0

pretty much what it says. i cant seem to create my scatterplot with the code that my prof basically hand fed to us

ggplot(df1, aes(mean, y)) +
geom_point() +
geom_errorbar(aes(ymin = lwr, ymax = upr, xmin = left, xmax = right))

the error message says this

Error in `geom_point()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in `FUN()`:
! `data` must be uniquely named but has duplicate columns
2
  • 1
    Welcome to SO! As the error message is telling you, your data contains columns with the same name. To make your code work you have to make the column names unique, e.g. try names(df1) <- make.unique(names(df1)). Still, you should check which (and why some) columns have the same name. For more help please provide a minimal reproducible example including a snippet of your data or some fake data best shared via dput(), ie.. run dput(head(df1)) and copy the output into your post.. Commented Oct 25, 2023 at 6:41
  • I agree with stefan's comment. I would add though that while make.unique(.) will fix the symptom, I'll emphasize a bit more stefan's note that "you should check" ... something in the previous processing of this data is either wrong (coder intent) or has failed to preserve unique names (bug or mis-use of function). Find whereever in your code path that created the non-unique names and fix that step, far far better than patching the symptom. Bottom line, while the error is from ggplot2, the problem is with the data, and we don't have that. Good luck! Commented Oct 25, 2023 at 12:16

1 Answer 1

0

p <- Canfuel %>% ggplot(mapping = aes(x = FuelConsCity, y = FuelConsHwy)) +

  • geom_point(color = "fuel_type") +
  • theme_bw()

p

Sign up to request clarification or add additional context in comments.

1 Comment

It says Error in geom_point(): ! Problem while converting geom to grob. ℹ Error occurred in the 1st layer. Caused by error: ! Unknown colour name: fuel_type Run rlang::last_trace() to see where the error occurred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.