It is a matter of taste whether one prefer to use ggplot or plot to produce his/her final plots (I actually use them both) but I find that once one knows a bit about these funny arguments like cex, pch or oma it quickly gives what you want. With all these tools in our hands we are now able to make our plots look just how we want them to. Note that the xpd argument can also be set within the par function, it is then applied to all subsequent plots. If it is set to TRUE all plot elements are clipped to the figure region (plot inner margins) and if it is set to NA you can basically add plot elements everywhere in the device region (plot inner margins outer margins). Legend(x=1,y=1.7,legend=LETTERS,col=unique(cols),pch=16,bty="n",xpd=NA)Īn important point to note here is that the xpd argument in the legend function which control if all plot elements (ie points, lines, legend, text …) are clipped to the plotting region if it is set to FALSE (the default value). #outer margins can also be used for plotting legend in themĬols<-rep(c("red","green","orange","yellow","black"),each=2) Mtext(text="A common y-axis label",side=2,line=0,outer=TRUE)Īnd we can also add a common legend: set.seed(20160228) Mtext(text="A common x-axis label",side=1,line=0,outer=TRUE) This comes especially handy for multi-panel plots: #this is particularly useful when having a plot with multiple panels and similar axis labels With outer margins we can write very long or very big axis labels or titles without having to “sacrifice” the size of the plotting region. This page documents the usage of the lower-level subplot module. Mtext(text="A very very long axis title\nthat need special care",side=2,line=0,outer=TRUE,cex=1.7) Plotly’s R graphing library makes it easy to create interactive, publication-quality graphs. #sometime this is not desirable so one may plot the axis text outside of the plotting area #one option would be to increase inner margin size Plot(1,1,ylab="A very very long axis title\nthat need special care",xlab="",type="n") #when axis label is long and one does not want to shrink plot area Outer margins can be handy in various situations: #Outer margins are useful in various context To write text in the outer margins with the mtext function we need to set outer=TRUE in the function call. Mtext(text=paste0("Outer line ",line),side=side,line=line,outer=TRUE)įrom this plot we see that we can control outer margins just like we controlled inner margins using the par function. Mtext(text=paste0("Inner line ",line),side=side,line=line) Disadvantages: just about everything else. Advantages: you get complete control over your layout. Do them by hand Manually combine your plots in graphics software outside of R. Plot(1,1,type="n",xlab="",ylab="",xaxt="n",yaxt="n") 1 Multipanel approaches in R To my knowledge, there are ve main approaches to multipanel layouts in R. Let’s directly dive into some code: #a plot has inner and outer margins To know more about plot customization read my first and second post. This is the third post in our series Mastering R Plot, in this one we will cover the outer margins.
0 Comments
Leave a Reply. |