My data set is in the form of a table made in praat, that contains the columns f220, f120, f280, and f180. Under each of those is a measurement associated with a specific word, such that the word in row 1 will have unique f220, f120, f280, and f180 values. My goal is to plot an arrow from x1=f220 y1=f120 to x2=f280 y2=f180. This is my table:
However, whenever I try to use f220, f120, f280, or f180 in ggplot, it treats the measurements as discrete values rather than being on a continuous scale. I believe that the content of each cell is treated as a factor rather than a numerical value. I have already tried to use as.numeric()
, however this returned incorrect values. I do get a graph with:
ggplot() +
geom_segment(data=ow, mapping=aes(x=f220, y=f120, xend=f280, yend=f180),
arrow=arrow(angle=5), size=.5, color="red")
however the axis is not scaled, plus I am unable to set any limits or reverse the axis getting the "discrete value supplied to continuous scale" error. This is what happens:
I am able to get what I want by manually creating a data frame with an ordered pair of all the relevant values, however as this is time consuming and I need to do this for 100+ more data sets, I would rather find a way of not simply copying and pasting the numbers. This is the manual data frame (this is the correct graph via the data frame):
dfow=data.frame(x=c(1126.519537,1034.584991,1277.922287,1304.417017,1312.378515,1336.947675,932.284623,1253.6823255372103,1291.853523,1184.573491), y=c(621.0741703,593.9790728,619.6623011,533.3008616,450.9261326,540.0055773,410.0854765,576.6145726,549.7064836,532.9992762), xv=c(1143.969311,1236.669227,1162.265314,1346.566912,1100.251361,1031.416842,1578.243306,1208.190102,1166.698588,1328.207814), yv=c(460.6605515,361.6829504,347.2567965,404.6473197,345.9352715,423.4654868,408.2602727,330.5207874,292.0723355,394.1734665))
ggplot() +
geom_segment(data=dfow, mapping=aes(x=x, y=y, xend=xv, yend=yv), arrow=arrow(angle=5),
size=.5, color="red") +
geom_point(data=dfow, mapping=aes(x=x, y=y), size=2, shape=2, color="red") +
scale_x_reverse() +
scale_y_reverse() +
xlab("F2(HZ)") +
ylab('F1(Hz)') +
xlim(2500, 500) +
ylim(800, 200)
In a previous project, I was able to make a point plot using the following code, with "story" being a similar table generated by praat, but only with f1 and f2.
ggplot(story, aes(y=f1, x=f2)) +
geom_text(aes(label = class, color=class)) +
scale_x_reverse() +
scale_y_reverse() +
xlab("F2(HZ)") +
ylab('F1(Hz)')
I used the exact same praat script to create both tables, except the current one shown was modified to have two f1 ant two f2 values (one at 20% and one at 80% of the vowel), so that I could create an arrow from the 20% to the 80% point in order to represent the movement of the vowel in articulatory space. I never had any trouble in this previous project, and have no idea why my numbers are being treated a factors in the current one.
Any help with being able to get the correct table without having to manually enter the values into a data frame would be greatly appreciated.