layout - R legend: placement and sizing of symbols and labels for barplots in base graphics -
i using layout create 15 panels: first 3 panels being titles followed 12 barplots using base r. want include legend multiple plots along title in 3rd panel.
there 3 legend items in horizontal legend. i'm struggling resize , position these elements fit neatly , legibly under title.
the default patch size large can find no way independently resize patch symbol , text (pt.cex not work, because not using point symbol). using cex = 0.5 resize legend gives me patch size want text far small (i want text cex = 1).
is there way resize symbols in legend independently of labels?
# layout graphs in grid of 3 cols 5 rows final <- layout(matrix(c(1:15), 5, 3, byrow = true)) plot.new() text(0.5, 0.5, "direction of wind gusts", cex = 1.5) # cex rescales text plot.new() text(0.5, 0.5, "direction of extreme wind gusts", cex = 1.5) plot.new() text(0.5, 0.5, "direction of plants", cex = 1.5) # add legend below third title text legtext <- c("shrub","graminoid","cushion") legend("bottom", legend=legtext, fill=gray(c(0.6, 0.3, 0.9)), horiz = true, x.intersp = 0.3, bty="n", cex = 0.5, inset = c(0,-0.3)) following code 12 barplots in remainder of grid.
i have tried workaround solves sizing problem seems make spacing impossible. workaround plot patches , text separately on top of each other. can tweak vertical offset position legend items.
however cannot work out how control horizontal spacing of legend elements 3 legend items fit in space. of legend truncated , not visible , patches , text not align horizontally (big gaps between them).
# workaround plot legend symbols (no labels) scaled 0.5 legend("bottom", legend= "", fill=gray(c(0.6, 0.3, 0.9)), horiz = true, x.intersp = 0.1, bty="n", cex = 0.5, inset = c(0,-0.3)) # legend labels, scaled 1 legend("bottom", legend = legtext, horiz = true, x.intersp = 0.02, bty="n", cex = 1, inset = c(0,-0.7)) i realise exporting or zooming plot layout can display things differently screen layout/resolution in r studio, still cannot adjust legend symbols , text fit neatly on 1 line.
Comments
Post a Comment