Reputation: 2077
I need to display a grid of plots for a data frame which is 213 x 4. When I use the following command in ggplot2, the plot is a long linear display of plots which are scrunched up
ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
I tried to use facet_wrap but I get an error
"Error in layout_base(data, vars, drop = drop) : At least one layer must contain all variables used for facetting"
The command I used for facet_wrap is as follows
ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) +
facet_wrap(. ~ bowler,scales = "fixed",ncol=4,drop=TRUE)+
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
How can I display as A x B rows by columns of plots?
Upvotes: 1
Views: 284
Reputation: 2077
Changed to the following
ggplot(data=r,aes(x=wicketPlayerOut,y=runs,fill=wicketPlayerOut)) +
facet_wrap( ~ bowler,scales = "fixed",ncol=4,drop=TRUE)+
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
and the display is now as nrow x ncol
Upvotes: 1