Skip to content

Instantly share code, notes, and snippets.

@jvcasillas
Last active January 22, 2018 02:25
Show Gist options
  • Save jvcasillas/86cec5f9f6b664ebfddddf472716927b to your computer and use it in GitHub Desktop.
Save jvcasillas/86cec5f9f6b664ebfddddf472716927b to your computer and use it in GitHub Desktop.
Example for plotting vowels using ggplot
# Plot vowel formants
# - Include elipses,
# - group/vowel means
# - greyscale
# Load tidyverse and phonR package (I choose this because you said you
# had alrady used it)
library(phonR)
library(tidyverse)
# Get vowels and check structure
data(indoVowels)
str(indo)
# Calculate gender by vowel means for F1 and F2
means <- indo %>%
group_by(., vowel, gender) %>%
summarize(., f1m = mean(f1), f2m = mean(f2))
# Plot it
ggplot(indo, aes(x = f2, y = f1, label = vowel, shape = vowel, lty = gender)) +
stat_ellipse(aes(lty = gender),
color = 'black', type = "norm",
geom = "polygon", alpha = 0.1) +
geom_text(data = means, aes(x = f2m, y = f1m, label = vowel),
size = 9, show.legend = FALSE, color = "grey40") +
scale_y_reverse() +
scale_x_reverse(position = "top") +
labs(ylab = "F1 (Hz)", xlab ="F2 (Hz)") +
scale_color_brewer(palette = "Set1") +
scale_linetype_manual(name = '', values = c('solid', 'dotted')) +
theme_bw(base_size = 12, base_family = "Times New Roman")
@jvcasillas
Copy link
Author

ggplot(testplot, aes(x = normF2, y = normF1, label = phoneme, shape = phoneme, lty = group)) +
  stat_ellipse(aes(lty = group), 
               color = 'black', type = "norm", 
               geom = "polygon", alpha = 0.1) +
  geom_text(data = means, aes(x = f2m, y = f1m, label = vowel), 
            size = 9, show.legend = FALSE, color = "grey40") + 
  scale_y_reverse() + 
  scale_x_reverse(position = "top") + 
  labs(ylab = "F1 (Hz)", xlab ="F2 (Hz)") + 
  scale_color_brewer(palette = "Set1") + 
  scale_linetype_manual(name = '', values = c('solid', 'dotted', 'dotdash')) + 
  theme_bw(base_size = 12, base_family = "Times New Roman")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment