guide_axis_scalebar {ggh4x} | R Documentation |
This axis guides draws a scale bar to indicate a distance rather than mark absolute values.
guide_axis_scalebar( title = waiver(), size = NULL, label = NULL, colour = NULL, color = NULL, just = 1, position = waiver() )
title |
A character string or expression indicating a title of guide.
If |
size |
A |
label |
A |
colour, color |
A |
just |
A |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
It is discouraged to use this guide in combination with a scale transformation.
A axis_scalebar
guide class object.
This axis guide has an alternative understanding of the following theme elements:
axis.ticks.*
An element_line()
to draw the scale bar itself.
axis.ticks.length.*
A unit()
indicating how far the scale bar should be placed from the
plot panel. Can be a negative unit to place the scale bar inside the
plot panel.
axis.text.*
The hjust
and vjust
parameters are used to justify the text along
the scale bar, instead of along itself, in the x
and y
directions
respectively.
Other axis-guides:
guide_axis_logticks()
,
guide_axis_manual()
,
guide_axis_minor()
,
guide_axis_nested()
,
guide_axis_truncated()
# A standard plot p <- ggplot(mpg, aes(displ, hwy)) + geom_point() # Guide as secondary axis p + guides(x.sec = "axis_scalebar") # Customising size and label p + guides(x.sec = guide_axis_scalebar(size = 0.5, label = "0.5 litre")) # Placing the scale bar on top of the plotting panel p + guides(x.sec = guide_axis_scalebar(just = 0.95)) + theme(axis.ticks.length.x.top = unit(-2, "lines")) # Adding arrows through the axis.ticks theme element p + guides(y.sec = guide_axis_scalebar(size = 10, label = "10\nmpg")) + theme(axis.ticks.y.right = element_line(arrow = arrow(ends = "both")))