library(tidyverse)
library(ElemStatLearn)
phoneme <- as_tibble(phoneme)
aa = phoneme %>%
filter(g == "aa")
aa[1:15, 1:256]
min_l = min( aa[1:15, 1:256] )
max_l = max( aa[1:15, 1:256] )
ii=1
plot( as.double(aa[ii, 1:256]), ylim=c(min_l,max_l), type="l", col="green",
xlab="Frequency")
for( ii in 2:15 ){
lines( as.double(aa[ii,]), col="green" )
}

library(reshape2)
aa2 <- aa %>%
dplyr::slice(1:15) %>%
dplyr::select(-g, -speaker) %>%
t %>% as.data.frame() %>%
dplyr::add_rownames() %>%
dplyr::select(-rowname) %>%
dplyr::mutate(id = 1:256) %>%
reshape2::melt(id.vars = "id")
ggplot2::ggplot(aa2) +
geom_line(aes(x = id, y = value, col = variable), show.legend = F) +
scale_x_continuous(breaks = seq(0, 250, 50)) +
scale_y_continuous(limits = c(min_l,max_l)) +
scale_color_manual(values = rep("green", 256)) +
xlab("Frequency") +
theme_classic()

Comment:
When manipulated the dataframe to perform the transposed matrix, the object under manipulation acquires the names of the varibles in each row (rownames
). So, to make the plot easier and make the df more elegant I think it is interesting to remove the names of the rows.
So it was necessary at first to include the names in the df and (dplyr::add_rownames()
) later to remove the column with the names of the rows (dplyr::select(-rowname)
) .
This gives a false illusion of error, but I performed in a redundant way to avoid using NULL
. See link.
Editing by Gregor's comment:
aa2 <- aa %>%
dplyr::slice(1:15) %>%
dplyr::select(-g, -speaker) %>%
t %>% as.data.frame() %>%
tibble::remove_rownames() %>% # Comment
dplyr::mutate(id = 1:256) %>%
reshape2::melt(id.vars = "id")