While working with scatter plots,box plots and how to visualise and analyse the data,I stuck up with this question.

How can I combine two different plots where in the each plot is between different variables.

This can be done using the package gridExtra in R.

Let’s take an example.

First lets create a data frame which contains information about age,salary,experience of employees of a company.

company=data.frame(list(“name”=LETTERS[1:25],”age”=sample(c(21:30),25,replace=T),”salary”=sample(25000:40000,25,replace=T),”experience”=sample(0:8,25,replace=T)))

Let’s create two different plots

q1=qplot(company$age,company$salary,geom = “boxplot”)

q2=qplot(company$experience,company$salary,geom = “point”)

and then add gridExtra package

library(gridExtra)

q1 and q2 plots can be combined into a single graph with grid.arrange function.

grid.arrange(q1,q2,ncol=2)

##ncol=2 will show you the plots in two different columns

Rplot

Note:You can even mention nrow if you want to show a number of plots in a specified number of rows and columns.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s