Erin-Rooney/XCT-freezethaw

Facet-wrap problem

Closed this issue · 11 comments

I am trying to create a two panel figure but can't seem to make it work.

@kaizadp

facet_wrap(~trmt, nrow = 2)

(~trmt) arranges it into columns, which is nullified by the nrow=2

try facet_wrap(trmt~, nrow=2)

a more elegant option is facet_grid(trmt~.), which will form a grid instead of wrapping the panels around.

So now I'm getting an error: At least one layer must contain all faceting variables: trmt.

  • Plot is missing trmt
  • Layer 1 is missing trmt

If I put trmt in quotations, then I get a different error: Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 180, 0

I think something is going wrong with my data again where it seems to be ignoring one of the samples in the "before" trmt. I'm not sure what is happening though, because last time this happened you caught the sample name error and I fixed it.

facet_grid(trmt~.)

I'm creating a new branch to work through the script.
Question -- do other parts of this script work for you? Other lines are also giving me errors, so I'm going to fix those.

Yes! Definitely having issues in other places in the code.

If you run the code below I think you can kind of see the issue with one sample seeming to have separated from the "before" trmt.

p + theme_er() + guides(fill = guide_legend(reverse = FALSE, title = "Bins"))

Yep, that's fixed now. I'm committing each change, so you can see what I'm doing.

Note: this is not how you use commits. As discussed yesterday, I'd normally lump all the edits into a single commit, like "cleaning minor issues". This is just so you can track and see the logic of the fixes.

Got it. I'm looking through the commits, which is super helpful. So it looks like I create a pull request and then that will merge the two branches? Is that right?

No, you don't do anything yet.
I create the pull request (PR). I will request your review on that. You review the changes, make sure it looks good, and then hit merge. then, when the branch is safe to delete, you delete it.

Got it.

The facet error wasn't because of the facet script, but because of how tool was previously created. If you try to run just p, you'd get an error there too, because the source data file was the wrong format.

Commit 51227b4 created tool as a dataframe, which automatically fixed the ggplot error.

Okay, this explains why I've gotten data frame related errors in the past. I think I've done this incorrectly other times too.

If you switch to dplyr for your subsetting needs, you won't have to worry about comma placement issues. See my example in the script.