Friday, April 5, 2013

RG#6: XY Scatter plot with box plot at margin

 # data
set.seed(123)
myd <- data.frame (X = rnorm (100, 10,4), Y = rnorm(100, 8,3))


# plotting

# plotting scatter plot,  ?par see fig, par will position your scatter plot
# parameters are set so that we can provide space for boxplot in margin
 par(fig=c(0,0.8,0,0.8), new=TRUE)
plot(myd$X, myd$Y, xlab="X", ylab="Y")


# now plotting first boxplot, in margin, you might need to change
# the numbers in parameters where you  to put the boxplots.

  par(fig=c(0,0.8,0.55,1), new=TRUE)
 boxplot(myd$X, horizontal=TRUE, col = "red", axes=FALSE)


# now plotting second boxplot, in margin
par(fig=c(0.65,1,0,0.8),new=TRUE)
boxplot(myd$Y, col = "blue", axes=FALSE)

# just giving title to the plot
mtext("Scatterplot with boxplot at margin", side=3, outer=TRUE, line=-3)



 
 
 

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.