I am using R core for plotting a grid of bar graphs. I use legend()
to draw a horizontally adjacent sequence of four filled rectangles with associated labels (drawn to the right of said rectangles). When a new device / window is first created, legend() renders the two innermost elements (ie, 2 filled rectangles and associated labels) of the legend, while the left and right elements are truncated from the device view.
If I maximize the size of the device / window to fill my laptop screen, and then re-run the rendering / plotting logic from R
, the legend then is properly surfaced -- comprising four columns and each element (ie, filled rectangle with label) is apportioned an equal swath of device space along the horizontal direction of the plot.
Why should device dimensions matter as to whether the legend()
contains all elements on the device / window? Is there a way to fix this?
Here is the exact call I make:
legend("bottom", legendLabels, fill=c(colors), xpd=NA, horiz=TRUE, bty="n", cex=1.0, inset=c(0, -0.5), xjust=0)
I set xpd=NA
because we are rendering the legend in the outer margins of the device view.