0

I'm attempting to make a scatterplot with ggplot. My data set is made up for 4 columns, three of which are factor variables and the fourth is a continuous variable.

'data.frame': 108 obs. of 4 variables:

$ Name : Factor w/ 3 levels "Con","Tag","Vel": 1 2 3 1 2 3 1 2 3 1 ...

$ Model: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...

$ IndexSeq : int 1 1 1 2 2 2 3 3 3 4 ...

$ Measurement : num 0.736 0.377 0.377 1.072 0.513 ...

plot5<-ggplot(plot.data.test, aes(IndexSeq, Measurement, color=Model)) + geom_jitter()+     
geom_hline(aes(yintercept=Measurement, color=Model), supplot)+
facet_wrap(~plot.data.test$Name)

"Supplot" contains the means by "Name" and by "Model", so there are 9 data points. I read numerous posts that said to add in the horizontal mean on a panel graph you need to have separate data.frame that contains the aggregated measurements. When I follow all of that, I get the following error:

Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(1L, 2L, 3L, 1L,  : replacement has 108 rows, data has 9

What am I doing wrong?

Cheers!

  • 3
    Welcome to StackOverflow. Please read [How to make a great reproducible example in R?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to make your question more likely to get an answer. Also you may want to take the [tour](https://stackoverflow.com/tour) and read [how to ask?](https://stackoverflow.com/help/how-to-ask) – M-- Dec 04 '17 at 15:08
  • Use `facet_wrap(~ Name)`, not `~plot.data.test$Name`. Maybe try adding `inherit.aes = FALSE` to the `geom_hline`? It's hard to tell - since the problem is with `supplot` you should share that data (well, you should share a little bit of both data frames to make things reproducible). – Gregor Thomas Dec 04 '17 at 15:22
  • Thank you Gregor! The change in facet_wrap() solved the issue! – Mircea_cel_Batran Dec 04 '17 at 19:21

0 Answers0