3

So I'm trying to plot two sets of data onto a single plot: one set (the BATH geom_text) to display 4 models' measurements, and another set (the geom_points) to display 77 different users' measurements.

preBATH<- monophs_allcoded %>%
filter(class == 'BATH') %>%
  group_by(user, model)%>%
  summarize(mean_pre_f1 = mean(f1_scaled_pre), mean_post_f1 = mean(f1_scaled_post), mean_pre_f2 = mean(f2_scaled_pre), mean_post_f2= mean(f2_scaled_post), model_f1 = mean(f1avg_scaledMODEL), model_f2 = mean(f2avg_scaledMODEL))%>%
  group_by(user) %>%
  ggplot() +
  geom_text(aes(x= model_f2, y = model_f1, label = 'BATH', color=model))+
  geom_point(aes(x= mean_pre_f2, y = mean_pre_f1, color =user))+
  scale_color_manual(values=allcolors)+
  guides(colour = guide_legend(ncol = 1)) +
  expand_limits(x = c(0,2000)) +
  expand_limits(y = c(0,600))  +
   xlab("Lobanov-normalized and scaled f2")+
  ylab("Lobanov-normalized and scaled f1")

preBATH <- preBATH + scale_y_reverse()
preBATH <- preBATH + scale_x_reverse()

output of ggplot preBATH

Ideally, I would like two separate color aesthetic mappings for each set of measurements. From what I have gathered, ggplot won't allow this. I've come up with a workaround, by generating a set of colors and specifying the first four as colors I want to use for the model measurements (allcolors) and specifying the colors manually in this line;

 scale_color_manual(values=allcolors)+

However, ggplot seems to ignore this command. I've tried scale_fill_manual with no luck. Any ideas on what I'm missing?

eipi10
  • 91,525
  • 24
  • 209
  • 285
dorothy
  • 53
  • 4
  • I believe it needs to be scale_colour_manual, color with a 'u'. – stevebroll Dec 13 '17 at 19:43
  • as a UK English speaker, this would be ironic if true - but that's not working either. Thanks. – dorothy Dec 13 '17 at 19:46
  • 1
    Without a reproducible example, it is difficult to say. What are the values of `user` or `model`? Try providing an example dataset and the minimum amount of code needed to generate the issue you're having. – Eric Watt Dec 13 '17 at 19:49
  • @stevebroll `scale_color_manual` and `scale_colour_manual` are the same commands. – M-- Dec 13 '17 at 19:49
  • You can’t map an aesthetic to more than one variable. And all the ggplot functions allow both spellings of color. – joran Dec 13 '17 at 19:50
  • That explains it, thank-you. Do you have any suggestions for how to achieve the desired output? – dorothy Dec 13 '17 at 19:59
  • Well, you're using the same text label ("BATH") for each model. Why not simply use the name of the model as the text label? – joran Dec 13 '17 at 20:01
  • I considered this, but this is one of 10 similar plots for different words, so wanted to include the word itself. Thanks for the suggestion, though! – dorothy Dec 13 '17 at 20:14
  • 4
    Use a filled point marker for the points (`shape=21` for filled circles) and then use `fill=user` in `geom_point`. But having, effectively, two color scales in the graph will probably be confusing. – eipi10 Dec 13 '17 at 21:35
  • [Here's an example](https://stackoverflow.com/a/29958948/496488) of using filled points to create the effect of two different color mappings. – eipi10 Dec 13 '17 at 21:58

0 Answers0