1

I'm running in a bit of a problem plotting some data with ggplot2: I want to use a facet_wrap over a variable AdultInputProp, but R doesn't find the variable and instead returns an Error in as.quoted(facets) : object 'AdultInputProp' not found. Now I understand that this simply means that R can't find this variable in the dataset used to plot, but if I ask ggplot2 to instead use the same variable for to create a shape scale, it works just fine. Any idea what the problem might be?

Sorry, I'm not too sure how to make a minimal working example with a generated df from scratch, so here's the df I'm using, and the code bellow. I've also tried using facet_grid instead of facet_wrap but ran into the same problem.

The code here with facets returns the above-mentioned error:

df.plot.GBPperAIP <- ggplot(df.sum.GBPperAIP,
                            aes(x=TestIteration, y=Error,
                                colour=GoalBabblingProp,
                                group=interaction(GoalBabblingProp,
                                                  AdultInputProp))) +
  facet_wrap(AdultInputProp) +
  xlab("Step") + ylab("Mean error") + theme_bw(base_size=18) +
  scale_colour_discrete(name = "Goal babbling proportion") +
  geom_line(position = position_dodge(1000)) +
  geom_errorbar(aes(ymin=Error-ci,
                    ymax=Error+ci),
                color="black", width=1000,
                position = position_dodge(1000)) +
  geom_point(position = position_dodge(1000),
             size=1.5, fill="white")

This other code, exactly the same except for the facet_wrap line deleted and with shape added works fine:

df.plot.GBPperAIP <- ggplot(df.sum.GBPperAIP,
                            aes(x=TestIteration, y=Error,
                                colour=GoalBabblingProp,
                                shape=AdultInputProp,
                                group=interaction(GoalBabblingProp,
                                                  AdultInputProp))) +
  xlab("Step") + ylab("Mean error") + theme_bw(base_size=18) +
  scale_colour_discrete(name = "Goal babbling proportion") +
  geom_line(position = position_dodge(1000)) +
  geom_errorbar(aes(ymin=Error-ci,
                    ymax=Error+ci),
                color="black", width=1000,
                position = position_dodge(1000)) +
  geom_point(position = position_dodge(1000),
             size=1.5, fill="white")
1
  • 3
    facet_wrap(~ AdultInputProp) Commented Aug 28, 2017 at 18:51

1 Answer 1

5

facet_wrap expects a formula, not just a naked variable name. So you should change it to

...
facet_wrap(~ AdultInputProp) +
...
Sign up to request clarification or add additional context in comments.

1 Comment

Stupidly I had tried using facet_wrap(.~AdultInputProp) and hadn't understood the error. Then stupidly hadn't tried it with facet_grid, where I guess it should have worked. Still annoyed by how hard R errors are to read for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.