Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems when columns identified in a loop #44

Open
oscci opened this issue May 5, 2018 · 1 comment
Open

problems when columns identified in a loop #44

oscci opened this issue May 5, 2018 · 1 comment

Comments

@oscci
Copy link

oscci commented May 5, 2018

I've got a script that works fine with individual pirate plots. I want to do 3 pirateplots side by side, so I am specifying the column name for x variable as mycol[i].
This works fine with a beanplot. It also works if there's just one pirateplot.
Using the loop with pirateplot, though, I get the error message
Error in var(y) : 'x' is NULL

Here is the script - I think it's the initial command to select data that throws it, rather than the use of i index in later bits of script.

for (i in 1:3){
pirateplot(all.data[,mycol[i]]~ all.data$randomtwininclude,
point.o = .5,
bar.f.o=.0,
inf.f.o=.2,
bean.b.o=.5,
jitter=.1,
ylab=mypheno[i],
ylim=c(myylim[i,1],myylim[i,2]),
main=paste0(mypheno[i]),
data=all.data
)
}

@ndphillips
Copy link
Owner

Hi there @oscci , the problem is in how you're specifying the formula. Formulas should only contained unquoted names of variables. In your code, you're including vectors in the formula -- this won't work.

If you want to create plots side by side, you could consider reshaping your data so that your 3 columns are represented as rows in a new variable called group (see the gather() function in the tidyverse https://tidyr.tidyverse.org/reference/gather.html) . Then, you can include the new variable as a second dependent variable in your formula.

# Get latest version from github to get the beside argument
devtools::install_github("ndphillips/yarrr", build_vignettes = TRUE)

library(yarrr)
library(tidyverse)

pirateplot(formula = weight ~ Diet + Time, 
                 data = ChickWeight %>% filter(Time < 5), 
                 beside = FALSE)

This will return the following plot:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants