Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot facet_wrap: At least one layer must contain all variables used for facetting

Tags:

facet-wrap

I am using the command

qplot(factor(ww), WeeklyYield, geom = "bar", fill = I("grey50"))+facet_wrap(~model+name)

to create a bar chart for every combination of model and name. However I get the following error message:

Error in layout_base(data, vars, drop = drop) : At least one layer must contain all variables used for facetting

I cannot uncode this message.

like image 325
user2145299 Avatar asked Mar 07 '13 17:03

user2145299


2 Answers

I'm not sure if it still helps after so much time, but I suspect the problem is that you're feeding a formula into facet_wrap(), whereas it can only take a variable, e.g. facet_wrap(~model).

If you want a formula, try facet_grid() as an alternative, e.g. facet_grid(.~model+name).

like image 93
Constantin Manuel Bosancianu Avatar answered Jan 03 '23 13:01

Constantin Manuel Bosancianu


Looks like ggplot does not found 'model' and /or 'name' column in your dataframe WeeklyYield. You should check with names(WeeklyYield)

like image 42
b_rousseau Avatar answered Jan 03 '23 12:01

b_rousseau