0

I have a twinData dataset that contains heights of twins (ht1 and ht2) and a sig_twin_cor table with a column called "similarity" which determines if the correlation between the heights is strong. I would like to facet the graph by cohort and zygosity, and then color the subplots with high similarity. I have the following code:

twinData %>% 
  left_join(sig_twin_cor, by = c("cohort"))  %>%
  ggplot(mapping = aes(ht1, ht2)) + geom_point(aes(color = ifelse(similarity == "Yes", "red", "black"))) +
  facet_grid(cohort ~ zygosity) +
  ggtitle("Cohort and Zygosity Facet Plot by Similarity")

but when I run it, an error says no applicable method for 'tbl_vars' can be applied to an object of class "c('gg', 'ggplot')". How could I solve this problem?

Jin Yu Li
  • 103
  • 3
  • 12
  • You are using the variable similarity in an ifelse. Have you initiated that variable prior to the code you posted? – Love Tätting Nov 15 '17 at 21:03
  • Is the sig_twin_cor table "organized" by cohort and zygosity? If so, you could try to join it beforehand with the "twin_data" dataset using a left join. This will provide you the "required" similarity column. – lbusett Nov 15 '17 at 21:24
  • @LoBu thanks for your help! Just edited my original question because of a new error. – Jin Yu Li Nov 15 '17 at 22:31
  • @JinYuLi It would be easier to advise if you provide a reproducible example of the dataset you're feeding into `ggplot()` (i.e. the result of `twinData %>% left_join(sig_twin_cor, by = c("cohort"))`). See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for how to do that. – Z.Lin Nov 18 '17 at 09:26

0 Answers0