library(grid)
grobDesc <- grob(label = "loon",
gp = gpar(col = "red"))
grid.newpage()
# Nothing is displayed
grid.draw(grobDesc)
textDesc <- l_updateGrob(grobDesc, grid::textGrob)
grid.newpage()
# label "loon" is shown
grid.draw(textDesc)
if(interactive()) {
# a loon plot with hidden labels
p <- l_plot(iris, showLabels = FALSE)
lg <- loonGrob(p)
# x label and y label are invisible
grid.newpage()
grid.draw(lg)
# show x label
lg <- l_instantiateGrob(lg, "x label: textGrob arguments")
# show y label
lg <- l_instantiateGrob(lg, "y label: textGrob arguments")
# reset margins
lg <- l_setGrobPlotView(lg)
grid.newpage()
grid.draw(lg)
# show axes
if(packageVersion("loon") < '1.3.8') {
lg <- l_instantiateGrob(lg, "x axis: .xaxisGrob arguments")
lg <- l_instantiateGrob(lg, "y axis: .yaxisGrob arguments")
} else {
lg <- l_instantiateGrob(lg, "x axis: xaxisGrob arguments")
lg <- l_instantiateGrob(lg, "y axis: yaxisGrob arguments")
}
lg <- l_setGrobPlotView(lg)
grid.newpage()
# the labels are too close to the plot
grid.draw(lg)
# reset the labels' positions
lg <- l_instantiateGrob(lg, "x label: textGrob arguments",
y = unit(-3.5, "lines"))
lg <- l_instantiateGrob(lg, "y label: textGrob arguments",
x = unit(-6.5, "lines"))
grid.newpage()
grid.draw(lg)
}
Run the code above in your browser using DataLab