I'm trying to create a scatter plot using ggplot. The x value goes roughly from 0-20, and the y value goes from 0-~50. The data is raw so it's not nice and neat and I need to plot a curved line through the majority of the data. The code I'm trying to use is

ggplot(temperature, Number.of.Fish,aes(x=Temperature,y=Number.of.Fish))+geom_smooth

But I keep getting an error message: error in inherits (mapping, "uneval"), could not find function "Number.of.Fish"


closed as off-topic by whuber Sep 8 '14 at 15:27

  • This question does not appear to be about statistics within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This sort of question is best asked on the ggplot2 mailing list $\endgroup$ – Dianne Cook Sep 7 '14 at 21:47
  • $\begingroup$ This question appears to be off-topic because it is only about software. If a reproducible example were provided it likely would be welcome on SO. $\endgroup$ – whuber Sep 8 '14 at 15:27

The correct code should be

ggplot(temperature,aes(x=Temperature,y=Number.of.Fish)) + geom_smooth()

You made two mistakes. First, the parenthesis () after geom_smooth and secondly, extra variable Number.of.Fish after the data frame temperature. Also, please always include a reproducible example when asking a question. This is what I did for you.

x <- 0:20
temperature <- data.frame(Temperature=x,Number.of.Fish = rnorm(mean=x, sd=2, n=21))
ggplot(temperature,aes(x=Temperature,y=Number.of.Fish)) + geom_smooth()
  • $\begingroup$ Thanks that really helps, but does it matter if x and y axis are unequal (number of fish 1:50, temperature 0:20.67)? $\endgroup$ – Francesca Sep 8 '14 at 7:41
  • 1
    $\begingroup$ lengths of x and y have to be same. If for one x you have multiple y, you may replicate same value of x. for example x <- c(1,1,1) and y <- c(20,32,45) so both vectors have same lengths. $\endgroup$ – Mahbubul Majumder Sep 8 '14 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.