Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Created November 28, 2017 06:44
Join TextGrid and Formant data output from Praat, then get mean F1 and F2
# How to export TextGrid and Formant data from Praat: http://recordit.co/ybhGxsf99a
# Make sure to setwd() to where annotations.csv and formants.csv are located
library(dplyr)
library(readr)
left_join(
read_csv("annotations.csv") %>% mutate(join_col = "temp"),
read_csv("formants.csv") %>% mutate(join_col = "temp")
) %>%
select(-join_col) %>%
filter(tmin >= `time(s)`, `time(s)` <= tmax) %>%
group_by(Vowel = text) %>%
summarise(
F1_average = mean(`F1(Hz)`),
F2_average = mean(`F2(Hz)`),
)
@HedvigS
Copy link

HedvigS commented Nov 28, 2017

I'd suggest adding this from line 17

-> Vowel_chart

ggplot(Vowel_chart, aes(x=F1_average, y=F2_average, label = Vowel )) + geom_point() + geom_text(aes(label=Vowel),hjust=0, vjust=0)

@HedvigS
Copy link

HedvigS commented Nov 28, 2017

Also: SO EXCITED THIS IS SO MUCH FUN I'M HAVING A GREAT TIME

@HedvigS
Copy link

HedvigS commented Nov 28, 2017

Oh, and you'll have to load ggplot2 for that.

@HedvigS
Copy link

HedvigS commented Nov 28, 2017

Here's the full script with my edits:
library(dplyr)
library(readr)
library(ggplot2)

left_join(
read_csv("annotations.csv") %>% mutate(join_col = "temp"),
read_csv("formants.csv") %>% mutate(join_col = "temp")
) %>%
select(-join_col) %>%
filter(tmin >= time(s), time(s) <= tmax) %>%
group_by(Vowel = text) %>%
summarise(
F1_average = mean(F1(Hz)),
F2_average = mean(F2(Hz)),
) -> Vowel_chart

ggplot(Vowel_chart, aes(x=F1_average, y=F2_average, label = Vowel )) + geom_point() + geom_text(aes(label=Vowel),hjust=0, vjust=0) -> Vowel_chart_plot

plot<- Vowel_chart_plot
pdf("My_first_vowel_plot_in_r.pdf", width=5, height=5)
plot
dev.off()

@fauxneticien
Copy link
Author

            _
           /(|
          (  :
         __\  \  _____
       (____)  `|
      (____)|   |
       (____).__|
        (___)__.|_____
                   SSt

@HedvigS
Copy link

HedvigS commented Nov 29, 2017

ggplot(Vowel_table, aes(x=F1_average, y=F2_average, label = Vowel )) + geom_point() + geom_text(aes(label=Vowel),hjust=-1, vjust=-1) + scale_y_reverse() + scale_x_reverse() -> Vowel_chart_plot
plot(Vowel_chart_plot)

@fauxneticien
Copy link
Author

@HedvigS — also should have noted F2 (associated with tongue frontness/backness) should be on the x-axis (another reversal!)

ggplot(Vowel_table, aes(x=F2_average, y=F1_average, label = Vowel )) +
geom_point() +
geom_text(aes(label=Vowel),hjust=-1, vjust=-1) +
scale_y_reverse() +
scale_x_reverse() -> Vowel_chart_plot

plot(Vowel_chart_plot)

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