0

I'm very very new to R, so thanks in advance for the help I did the lda analysis on my dataset (tme.lda), in the console I get all my results with LD1, LD2, LD3, LD4, LD5 and LD6 but when I try to plot it I tried a lot of different methods but I get every kind of error: Error LD1 object not found - Error in fortify - Error in as.data.frame just to say a few.

This is my dataset:

dput(head(tme.lda))
structure(list(Word = structure(1:6, levels = c("bene", "bile", 
"casa", "come", "posso", "tutto", "vero"), class = "factor"), 
   f0min = c(184L, 193L, 189L, 199L, 175L, 144L), f0max = c(229L, 
   226L, 198L, 225L, 192L, 188L), F1 = c(600L, 347L, 980L, 531L, 
   550L, 432L), F2 = c(2406L, 2695L, 1759L, 997L, 996L, 1901L
   ), F4 = c(4125L, 4403L, 3837L, 3988L, 3909L, 4171L), max_F0 = c(143L, 
   130L, 124L, 133L, 123L, 120L)), row.names = c(NA, 6L), class = "data.frame")

And this is the code I wrote, how can I get from here the scatterplot LD1 vs LD2?

View(tme.lda)
#lDFA analysis with "WORD" as grouping factor
tme.lda<-cbind(tme[,5],tme.lda[,1:6])
names(tme.lda)
#> [1] "tme[, 5]" "f0min"    "f0max"    "F1"       "F2"       "F4"       "max_F0" 
names(tme.lda)=c("Word","f0min","f0max","F1","F2","F4","max_F0")
names(tme.lda)
#> [1] "Word"   "f0min"  "f0max"  "F1"     "F2"     "F4"     "max_F0"
library(MASS)
lda(Word~f0min+f0max+F1+F2+F4+max_F0,data = tme.lda)

I tried this:

plot(Word, panel = tme.lda, abbrev = FALSE, xlab = "LD1", ylab = "LD2")
plot(x, panel = panel.lda, cex = 0.7, dimen=2, abbrev = FALSE, xlab = "LD1", ylab = "LD2")
ggplot(Word, panel = tme.lda, cex = 0.7, dimen=2, xlab = "LD1", ylab = "LD2")
ggplot2::aes(LD1,LD2) (Word, panel = tme.lda, cex = 0.7, dimen=2, xlab = "LD1", ylab = "LD2")
plot.lda<-lda(Word~f0min+f0max+F1+F2+F4+max_F0,data = tme.lda)

ggp <- ggplot(plot.lda, aes(x = LD1, y=LD2)) +
  geom_point(mapping = aes(colour=Word)) +
  ggtitle("LD1 Vs. LD2")

ggp <- ggplot(plot.lda, aes(x = LD1, y=LD2)) 

Just to say a few things I tried

  • Hi there and welcome to SO. Please share a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) or [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with an example input and your expected output. – Martin Gal Dec 27 '22 at 23:06
  • This is a part of my dataset via dput, hope it's understandable: structure(list(Word = structure(1:6, levels = c("bene", "bile", "casa", "come", "posso", "tutto", "vero"), class = "factor"), f0min = c(184L, 193L, 189L, 199L, 175L, 144L), f0max = c(229L, 226L, 198L, 225L, 192L, 188L), F1 = c(600L, 347L, 980L, 531L, 550L, 432L), F2 = c(2406L, 2695L, 1759L, 997L, 996L, 1901L ), F4 = c(4125L, 4403L, 3837L, 3988L, 3909L, 4171L), max_F0 = c(143L, 130L, 124L, 133L, 123L, 120L)), row.names = c(NA, 6L), class = "data.frame") – Debora Cinganelli Dec 27 '22 at 23:23
  • Please edit your question and poste the `dput()` there. This shouldn't be a comment. :) – Martin Gal Dec 27 '22 at 23:24
  • You could try `plot(plot.lda$scaling[, "LD2"], plot.lda$scaling[, "LD1"])`. Not sure if this is what you are looking for. Or with `ggplot` : `plot.lda$scaling %>% as_tibble() %>% ggplot(aes(x = LD1, y = LD2)) + geom_point() + ggtitle("LD1 Vs. LD2")`. – Martin Gal Dec 27 '22 at 23:35

0 Answers0