0

Hi everybody I have 3 plots with density bars on either axis which I have done this way (here is a simpler form presented with only 3 ordinary plots but the other parts are necessary as required for a more complicated function which I have left off here just for the ease of viewing)

     scatterBar.Norm <- function(x,y) {
     zones <- matrix(c(2,0,1,3), ncol=2, byrow=TRUE)
     layout(zones, widths=c(5/7,2/7), heights=c(2/7,5/7))
     title("My Title", outer=TRUE);
     par(mar=c(3,3,1,1),mgp=c(2,1,0))
     plot(1:10,  xlab="Magnification", ylab="residue", col=2)
     par(mar=c(0,3,1,1))
     plot(1:10,  xlab="Magnification", ylab="residue",col=3)
     par(mar=c(3,0,1,1))
     plot(1:10,  xlab="Magnification", ylab="residue", col=4)}

     scatterBar.Norm(2,3)

The problem : Firstly the The plot title the "My Title" part is going out of the canvas , how to fix it ?

Thanks for the much needed help in advance.

Ayan Mitra
  • 497
  • 1
  • 8
  • 20
  • 3
    Why are you using `attach` on `b` and `e2` at the same time? They have the same variable names. You should avoid using `attach` for exactly this reason. – sebpardo Apr 22 '15 at 18:41
  • Without sample data, this problem isn't [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). If we can't re-create the plot ourselves, it's not easy to help. Also, make sure you post a *minimal* reproducible example. Take out any code that's not necessary to reproduce the problem. The few number of lines there are, the easier it is to find the problem. – MrFlick Apr 22 '15 at 18:56
  • Use either cex.main to reduce the font size or "\n" to split the title into multiple lines. And _never_ use attach! – IRTFM Apr 22 '15 at 19:01
  • Hi okay I have put up an edited version with simpler lines if you all can help – Ayan Mitra Apr 23 '15 at 12:43

1 Answers1

1

You've instructed R to plot the title in the outer margin, but (at least in your example) you haven't set up that margin. The following should work:

scatterBar.Norm <- function(x, y) {
  zones <- matrix(c(2, 0, 1, 3), ncol=2, byrow=TRUE)
  layout(zones, widths=c(5, 2), heights=c(2, 5))
  par(mar=c(3, 3, 1, 1), mgp=c(2, 1, 0), oma=c(0, 0, 3, 0))
  plot(1:10, xlab="Magnification", ylab="residue", col=2)
  par(mar=c(0, 3, 1, 1))
  plot(1:10, xlab="Magnification", ylab="residue", col=3)
  par(mar=c(3, 0, 1, 1))
  plot(1:10, xlab="Magnification", ylab="residue", col=4)
  title("My Title", outer=TRUE)
}

plot.new()
scatterBar.Norm(2, 3)

enter image description here

jbaums
  • 27,115
  • 5
  • 79
  • 119