# [R tutorial] Plotting within the figure margins

#### TheEcologist

##### Global Moderator
We had a reviewer request this:

"Consider putting an extra vertical arrow on the outside of each panel of Figs 3 & 4 (or at least Fig 3) with words indicating which directions the annual and rare strategies are along the scale (the numbers indicating the amount are not intuitive)."

I just figured out how to do this, so I though I might share it:

Code:
# make a plot
plot(1:10,rnorm(10,0,0.2)*1:10,ylab='',xlab='')
# key is to add a new layer, without margins
parsave <- par(new = TRUE,  mar = c(0,0,0,0))
# set up this layer with easy coordinates x[0,1] and y[0,1]
plot(0,0,xlim=c(0,1),ylim=c(0,1),type='n',xlab='',ylab='',col='white')

text(0.5,-0.02, 'increasing values')

text(-0.03,.5, 'increasing values', srt=90)

text(0.55, 0.025,expression(beta))
text(0, 0.55,expression(alpha))

# plot parameters  reset to prior values
par(parsave)

#### Dason

Hey thanks. I don't use base plot much anymore (I've gone over the dark ways of ggplot2) but I think I've wondered how to do something similar to this in the past. It makes sense what's going on and thanks for sharing!

#### TheEcologist

##### Global Moderator
Hey thanks. I don't use base plot much anymore (I've gone over the dark ways of ggplot2) but I think I've wondered how to do something similar to this in the past. It makes sense what's going on and thanks for sharing!
He Dason, maybe you can convince me but I havent seen anything ggplot2 can do that I cant through the 'base plot' options. As far as I know ggplot2 is just a (useful) bunching of automation scripts that create fancy but common graphs using both base and lattice graphics..

I tend not to use that.. because well I like screwing around with graph scripts (its therapy for me).. So call me a nerd/geek/freak but I like making fancy graphs using the base package from scratch

That said.. I am not too proud to rummage through the ggplot2 code for useful tricks.. nope I'm not above that

#### bugman

##### Super Moderator
Thanks for posting this The Ecologist.

I appreciate members posting plotting tips, its very useful!!

For what its worth, I am on the fence with the above: I generally construct plots from scratch because I llike the freedom. However, recently I have been using Lattice and grid alot. GGPLOTS looks great, but I find them less intuative so have steered away from them a bit.

#### Dason

In terms of ggplot2 I know that you could do all the stuff you can do with ggplot in base/trellis graphics. But it does make your life a lot easier in some regards depending on what you're trying to do. I know when working with some of my clients I've been able to produce some really nice plots on the spot (for things I didn't think of before hand) that really show what I'm trying to get it really quickly.

Other reasons that it's useful can be found here. I suggest looking at some of the case studies. I really like the 'Flying over the usa' example but it's actually nice to see the videos produced for that one in particular.

#### bugman

##### Super Moderator
:tup:

Indeed! I was looking for that yesturday. I remebered it was TART that set the challange!!

Thanks again The Ecologist!

#### bugman

##### Super Moderator
I suggest looking at some of the case studies. I really like the 'Flying over the usa' example but it's actually nice to see the videos produced for that one in particular.
Thanks for the link Dason. It looks pretty cool. I'll have a play with it when I can access a non-work computer that bans everything!