Description Usage Arguments Examples
The default abline of ggplot2 will exceeds the breaks and goes from one set of limits to the next. This is a modified verions that respect one will not exceed the extrema of the x and y-breaks.
1 2 3 4 5 6 7 8 9 10 |
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
method |
Either "breaks" (default) to respect the extrema of the axes or "ggplot2" to obtain the ggplot2 behavior. |
... |
Other arguments passed on to |
slope |
Parameters that control the
position of the line. If these are set, |
intercept |
Parameters that control the
position of the line. If these are set, |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | library(ggplot2)
library(jaspGraphs)
dfRect <- data.frame(xmin = -10, ymin = -10, xmax = 10, ymax = 10)
basePlot <- ggplot(data = dfRect, aes(xmin = xmin, ymin = ymin, ymax = ymax, xmax = xmax)) +
geom_rect(fill = NA, color = "black") +
geom_rangeframe() +
themeJaspRaw(legend.position = "right")
slopes <- seq(-5, 5, length.out = 15)
ints <- seq(-2, 2, length.out = length(slopes))
basePlot +
geom_abline2(intercept = ints - 2, slope = slopes, method = "breaks", color = "green") +
geom_abline2(intercept = ints + 2, slope = slopes, method = "ggplot2", color = "red") +
ggtitle("specify 'method' manually")
dfAbline <- data.frame(
intercept = -9:8,
slope = 0.35,
method = rep(c("ggplot2", "breaks"), 9)
)
basePlot +
geom_abline2(data = dfAbline, mapping = aes(
intercept = intercept, slope = slope, method = method, color = method
), show.legend = TRUE) +
ggtitle("specify 'method' through aes")
basePlot + geom_abline2(data = dfAbline, mapping = aes(
intercept = intercept, slope = slope, color = method
)) +
ggtitle("if method is not specified, 'breaks' is used as a default")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.