How to use facet_wrap or grid to combine these two separate code

r
visualization
datavisualization
facet

#1

Hi Friends,

I am using below two line of code to analyze my data in two range of salaries, so I have taken subset, can someone help me to combine these two line of code using facet_wrap or facet_grid or any other technique

ggplot(auto[auto$income<919400,],aes(type))+geom_bar(aes(fill=type))

ggplot(auto[auto$income>=919400,],aes(type))+geom_bar(aes(fill=type))


#2

Here is a technique:

Use the package gridExtra.

If p1 and p2 are your two plots from ggplot, you can try
grid.arrange(p1,p2)


#3

No actually I want to achieve the output of above two line of code by just using single line command, I mean I want to give pass full data frame like below :slight_smile:

ggplot(auto[auto,aes(type))+geom_bar(aes(fill=type)) + and then anything here

How can I achieve that …


#4

You can refer to this blog, it might give you some idea. I think you can do it by defining a new factor variable incomeLevel with values High/Low .

Blog: www.markhneedham.com/blog/2014/07/25/r-ggplot-plotting-back-to-back-charts-using-facet_wrap/