I have two ggplots. The first 1 looks like this:
ggplot(nurse, aes(x = nurse$z2.bk, y = nurse$z1.bk, color = nurse$phoneme)) +
geom_point() +
scale_x_reverse() + scale_y_reverse() +
scale_color_discrete() +
theme_classic()
I then created a subset which calculates the z1.bk averages and z2.bk for each of the phoneme categories. mean_F1 = the z1.bk average and mean_F2 = the z1.bk average.
vowel mean_F1 mean_F2
<fct> <dbl> <dbl>
1 Er 0.00830 0.612
2 Ir -0.0433 0.0456
3 Vr 0.0365 -0.576
I then created another ggplot (below) for these values and labelled them according to the nurse$phoneme values. I just renamed them here to vowels to keep everything a bit cleaner.
ggplot(means, aes(x = mean_F2, y = mean_F1, label = vowel)) +
geom_label() +
scale_x_reverse() + scale_y_reverse() +
theme_classic()
I now wanted to overlay them, so that the labels are displayed above the other points in the corresponding colour, i.e. Er in red.... I tried the following but got an error message.
ggplot(nurse, aes(x = nurse$z2.bk, y = nurse$z1.bk, color = nurse$phoneme, label = means$vowel)) +
geom_point() +
geom_label(data = means, aes(x = mean_F2, y = mean_F1)) +
scale_x_reverse() + scale_y_reverse() +
theme_classic()
Error: Aesthetics must be either length 1 or the same as the data (563): label
If I change 'label = means$vowel' to just 'vowel', I get another error message saying the object can't be found. If I change it to nurse$phoneme, I get this error message Error: Aesthetics must be either length 1 or the same as the data (3): colour, label.
How do I combine them properly? If I need to supply you with more data, just let me know. And thanks in advance!


ggplot2::annotate()to avoid a second plot.