4

I am experiencing the similar problems seen in:

  1. Main title at the top of a plot is cut off
  2. R: Titles cut in half with par()

and i tried the solutions suggested in both posts.

my code used to plot my hclust:

plot(hclust.train, hang = -1)

here's how my hclust plot look like: enter image description here

as suggested in the first post mentioned above, i tried:

par(oma=c(0,0,2,0))

to add border padding; however, the plot with the border look like this: enter image description here

it's simply the cut off version but moved down a bit...

here's how my clusplot plots look like (same problem):

enter image description here

and with the border added: enter image description here

i've also tried using the argument "mar=c(0,0,2,0)", as suggested in the 2nd post mentioned in the beginning, but the result is the same as adding the border padding.

any help is appreciated.

Edit: Thanks to Ben Bolker for a simple quick solution. After using his suggested code:

par(xpd=NA,oma=c(0,0,2,0))

i got the following improved version: enter image description here

my last question would be, how to get rid of the border line that's going through the title, OR move the title position above that border line? Thank you!

Community
  • 1
  • 1
alwaysaskingquestions
  • 1,595
  • 5
  • 22
  • 49
  • hard to say without a reproducible example. Try `par(xpd=NA,oma=c(0,0,2,0))` ? – Ben Bolker Mar 14 '16 at 02:52
  • hi @BenBolker, thank yo uso much for your suggested solution! i've edited my question to incorporate your suggestion, but i have some more question regarding clean up. would you be able to help as well? thank you! – alwaysaskingquestions Mar 14 '16 at 02:57

1 Answers1

4

You didn't give a reproducible example, but I can reproduce this if I set my margins to all-zero; I can work around it with par(xpd=NA)

hc <- hclust(dist(USArrests), "ave")
plot(hc)  ## looks OK

Setting the margins to zero cuts off the title:

par(mar=c(0,0,0,0))
plot(hc)  ## cut off

Setting the outer margin doesn't help:

par(mar=c(0,0,0,0),oma=c(0,0,2,0)) 
plot(hc)

Setting par(xpd=NA) does help:

par(mar=c(0,0,0,0),xpd=NA)
plot(hc)

If I add box() I get a border line that cuts through the title. The best thing would be to not set the margins to zero, or to set par(mar=c(0,0,2,0)) to make sure there's room for the title at the top, or to use par(oma=c(0,0,2,0)) and then use mtext() to add the title by hand.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453