3

I have a data.table I'm trying to plot facets with ggplot and I'm getting the error listed below. Thanks in advance for any help.

require(data.table, ggplot2)

dt <- as.data.table(read.table(h=T, 
text="ROW mode resbin V1
0   RD   50.0  0
1   RD   50.0  0
2   RD   50.0  0
0   RD   33.3  0
1   RD   33.3  0                  
1   PV    7.5  1
2   PV    7.5  0
0   PV    6.0  1
1   PV    6.0  1
2   PV    6.0  1"))


ggplot(dt, aes(x = factor(resbin), y = V1, group=1)) + 
geom_point(aes(color=factor(mode)), size=3) +
geom_line() +
facet_wrap(~factor(ROW), ncol=2)

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

1 Answer 1

2

Something funny is going on that I don't fully understand. This seems to work for me:

dt <- as.data.table(read.table(h=T, 
text="grp mode resbin V1
0   RD   50.0  0
1   RD   50.0  0
2   RD   50.0  0
0   RD   33.3  0
1   RD   33.3  0                  
1   PV    7.5  1
2   PV    7.5  0
0   PV    6.0  1
1   PV    6.0  1
2   PV    6.0  1"))


ggplot(dt, aes(x = factor(resbin), y = V1)) + 
geom_point(aes(color=factor(mode)), size=3) +
geom_line(aes(group = 1)) +
facet_wrap(~grp, ncol=2)

I seemed to need to change the column name and remove factor() from it. But I only tested this briefly.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried changing the name of the from "mode" to "my.mode" and removing the factors and it still blew up. I also prefer reading the data in using as.data.frame(). This is a good one...
That worked. Thanks for the help. I'll have to remember that ggplot doesn't like columns named ROW.
@NathanG Disliking ROW as a column name seems very suspicious to me. I'm planning on asking around to verify that that's a bug.
other names that it's not going to like are COL and PANEL github.com/hadley/ggplot2/blob/…
and SCALE_X, SCALE_Y, AXIS_X and AXIS_Y. See github.com/hadley/ggplot2/issues/838

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.