coord_capped_cart | R Documentation |
Caps the axis lines to the outer ticks to e.g. indicate range of values.
Methods correspond to coord_cartesian
and coord_flip
coord_capped_cart(
xlim = NULL,
ylim = NULL,
expand = TRUE,
top = waiver(),
left = waiver(),
bottom = waiver(),
right = waiver(),
gap = 0.01
)
coord_capped_flip(
xlim = NULL,
ylim = NULL,
expand = TRUE,
top = waiver(),
left = waiver(),
bottom = waiver(),
right = waiver(),
gap = 0.01
)
capped_horizontal(capped = c("both", "left", "right", "none"), gap = 0.01)
capped_vertical(capped = c("top", "bottom", "both", "none"), gap = 0.01)
xlim , ylim |
Limits for the x and y axes. |
expand |
If |
top , left , bottom , right |
Either a function returned from
|
gap |
Both ends are always capped by this proportion. Usually a value between 0 and 1. |
capped |
Which end to cap the line. Can be one of (where relevant):
|
This function is a simple override of coord_flex_cart
and coord_flex_flip
,
which allows shorthand specification of what to cap.
NB! A panel-border is typically drawn on top such that it covers tick marks,
grid lines, and axis lines.
Many themes also do not draw axis lines.
To ensure the modified axis lines are visible, use
theme(panel.border=element_blank(), axis.lines=element_line())
.
library(ggplot2)
# Notice how the axis lines of the following plot meet in the lower-left corner.
p <- ggplot(mtcars, aes(x = mpg)) + geom_dotplot() +
theme_bw() +
theme(panel.border=element_blank(), axis.line=element_line())
p
# We can introduce a gap by capping the ends:
p + coord_capped_cart(bottom='none', left='none')
# The lower limit on the y-axis is 0. We can cap the line to this value.
# Notice how the x-axis line extends through the plot when we no long
# define its capping.
p + coord_capped_cart(left='both')
# It it also works on the flipped.
p + coord_capped_flip(bottom='both')
# And on secondary axis, in conjuction with brackets:
p +
scale_y_continuous(sec.axis = sec_axis(~.*100)) +
scale_x_continuous(sec.axis = sec_axis(~1/., name='Madness scale')) +
coord_capped_cart(bottom='none', left='none', right='both', top=brackets_horizontal())
# Although we cannot recommend the above madness.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.