Closed valerief closed 8 years ago
ok, please try this:
devtools::install_github("drammock/phonR", ref="1.0-7")
library(phonR)
diph_linetype <- ifelse(subdata$env %in% "point", "dashed", "solid") # swap dashed & solid as desired
diph_linetype <- diph_linetype[!duplicated(subdata$rime)]
with(subdata,
plotVowels(f1=F1, f2=F2, vowel=rime, group=rime,
var.col.by=rime, var.style.by=env, lty=rep(c("dashed", "solid"),10),
plot.tokens=F, plot.means=T, pch.tokens="", pch.means=rime, cex.means=1.5,
ellipse.line=T, ellipse.fill=F, ellipse.conf=0.6827,
diph.arrows=T, diph.args.tokens=NULL, diph.args.means=list(lwd=3, lty=diph_linetype),
diph.label.first.only=TRUE, diph.mean.timept=4, diph.smooth=T,
col=rep(c("seagreen", "orangered2", "purple", "green3", "tan1", "dodgerblue3", "gray50", "tan", "steelblue2", "orchid"), 2),
pretty = T, main = "Test plot", sub = "no dashed lines", cex.main=1.2, cex.sub=0.9 ))
note that diph_linetype
is passed in as part of diph.args.means
Something's wrong. When I first tried to install, it told me I needed Rtools, but I wasn't sure I did everything right, so since my version of R was old, I uninstalled R, Rstudio, and Rtools and then installed R 3.2.2, R studio 0.99.489, and Rtools 3.2. The exact code I used after that is attached, but the result was the same as before I reinstalled everything: no diph lines at all. Error in plot.xy(xy.coords(x, y), type = type, ...) : invalid plot type I've tried removing lty=diph_linetype, but I still get the same error and no diph lines. Everything else seems to be working right when I modify or remove parts. test2.pdf attempt2.txt
something is definitely wrong, but I don't think it's with phonR. It would help if you could to traceback()
right after you get the error, and include that here. Here's what I get using the code in your most recent attached script:
This is on Linux, so I'll try later today on Windows, but I don't really expect there to be a difference; the changes I made to fix this don't touch the system-specific bits of the code.
note that there is at least one remaining problem with my version, which is that the dashed arrows have dashed arrowheads. There is also the question of getting diphthong lines to pick up the linetype spec from the lty
and var.style.by
arguments, instead of having to pass it directly as part of the diph.args.means
list (which was a dirty hack to get it working quickly for you).
turns out this was a phonR bug (related to internal use of as.data.frame
without specifying stringsAsFactors=FALSE
, if you're curious). I should have a fix posted in a few hours.
OK, I've (finally) tracked down and fixed this for both diphthong tokens and diphthong means. Can you try the 1.0-7 branch again and see if it does what you want?
devtools::install_github("drammock/phonR", ref="1.0-7")
library(phonR)
with(subdata,
plotVowels(f1=F1, f2=F2, vowel=rime, group=rime,
var.col.by=rime, var.style.by=env,
lty=c("dotted", "solid"), #"dashed",
plot.tokens=FALSE, plot.means=TRUE, pch.tokens="",
pch.means=rime, cex.means=1.5,
ellipse.line=TRUE, ellipse.fill=FALSE, ellipse.conf=0.6827,
diph.arrows=TRUE, diph.args.tokens=NULL,
diph.args.means=list(lwd=3),
diph.label.first.only=TRUE, diph.mean.timept=4, diph.smooth=TRUE,
col=c("seagreen", "orangered2", "purple", "green3", "tan1",
"dodgerblue3", "gray50", "tan", "steelblue2", "orchid"),
pretty=TRUE, main="Test plot", sub="no dashed lines",
cex.main=1.2, cex.sub=0.9))
Note that it should now pick up the lty
argument without you having to specially pass it as part of diph.args.means
(though you can still do that if you want the diphthong lines to have different line types than the ellipses.
@valerief did the updated solution work for you?
Yes, thank you. But now it's labeling with the indeces of the indicated column (rime) instead of the labels. Have I swapped something?
levels(subdata$rime) [1] "AAD" "AED" "AEG" "AHD" "EHD" "EHG" "EYD" "EYG" "IHD" "IHG" "IYD" "IYG" "OWD" "UHD" "UWD"
F1 <- as.matrix(cbind(subdata[,13:19])) F2 <- as.matrix(cbind(subdata[,24:30])) with(subdata, plotVowels(f1=F1, f2=F2, vowel=rime, group=rime, var.col.by=vowel_label, var.style.by=env, lty=c("dotted", "solid"), #"dashed", plot.tokens=FALSE, plot.means=TRUE, pch.tokens="", pch.means=rime, cex.means=1.5, ellipse.line=TRUE, ellipse.fill=FALSE, ellipse.conf=0.6827, diph.arrows=TRUE, diph.args.tokens=NULL, diph.args.means=list(lwd=3), diph.label.first.only=TRUE, diph.mean.timept=4, diph.smooth=TRUE, col=c("seagreen", "orangered2", "purple", "dodgerblue3", "green3", "tan1", "gray50", "tan", "steelblue2", "orchid"), pretty=TRUE, main="Test plot", sub="dashed lines", cex.main=1.2, cex.sub=0.9))
hmm, maybe try pch.means=as.character(rime)
to convert the factor to a character vector. Since pch
can be either numeric or string, I can't safely always convert it to character behind the scenes.
FYI, the reason you get that error and I don't is that I have run options(stringsAsFactors=FALSE)
so that character vectors don't automatically get converted to factors when added to a data.frame
. Personally I've found it extremely helpful to have that option set, but be warned that the call to options()
is persistent across sessions and has a slight risk of breaking code that used to work if you happen to have done something that relied on the implicit factor conversion that was happening.
That did it, thanks! And that makes sense about options().
The line type is configurable for poly.lines and ellipses, but I'd also like to vary it for the diph lines (eg to have dashed for the -d means and solid for -g ("point" and "prevelar" under the "env" column in my data)). Am I doing something wrong? (Don't worry about the colors in the example - I still have to rearrange the vowels.) Sample data and output plot attached.
test.pdf
subdata.txt