0

My problem: I try to add average points of the sample to the plot, but the R doesn't allow me to, because the size of the data is not the same as the original one. I tried to make it so, that on the geom_point() layer the x and y are the same as the one on ggplot but still I get error: Error: Aesthetics must be either length 1 or the same as the data (3): x and y

ggplot(data = all_avg, aes(x = year_film, y = avg_rating, col = Award)) +
  geom_point() +
  geom_point(data = all_avg_means, size = 2, aes(x = all_avg$year_film, y = all_avg$avg_rating))

I simply want to add three averages to the plot.

use1883
  • 59
  • 7
  • Can you provide a reproducible example of your data ? see: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. By eye, the height of TRUE seems a little bit higher. Take a look by "zooming" on it using `coord_cartesian(ylim = c(5,7.5))` – dc37 Apr 23 '20 at 04:08
  • @dc37 Here I updated my question. I want to add three mean data points to my plot, but it doesn't allow me, saying that the aesthetics should agree between layers. I on purpose put the same aesthetics to geom layer as to ggplot but still got the error. – use1883 Apr 23 '20 at 04:19
  • please provide an example fo what `all_avg`, `all_avg_means` looks like in order we can guide you toward the solution. First, point do not use $ to design columns inside `aes`. – dc37 Apr 23 '20 at 04:22
  • 1
    Remove `all_avg$` from the second call to `geom_point`. – Rui Barradas Apr 23 '20 at 04:24
  • @RuiBarradas It's the same error then. – use1883 Apr 23 '20 at 05:00
  • Can you post sample data? Please edit **the question** with the output of `dput(all_avg)`. Or, if it is too big with the output of `dput(head(all_avg, 30))`. – Rui Barradas Apr 23 '20 at 07:07
  • Does this answer your question? [I am trying to plot geom\_bar onto ggplot, but geom\_bar has a differing sample source and R pops out an error](https://stackoverflow.com/questions/61378114/i-am-trying-to-plot-geom-bar-onto-ggplot-but-geom-bar-has-a-differing-sample-so) – nikn8 Apr 23 '20 at 10:48
  • you mustn't post the same Q again n again. @dc37 Not sure how to flag such event at SO. – nikn8 Apr 23 '20 at 10:51

0 Answers0