# Use the devtools package
# install.packages("devtools")
devtools::install_github("slowkow/ggrepel")
Options
Options allow us to change the behavior of ggrepel to fit the needs
of our figure. Most of them are global options that affect all of the
text labels, but some can be vectors of the same length as your data,
like nudge_x or nudge_y.
Option
Default
Description
seed
NA
random seed for recreating the exact same layout
force
1
force of repulsion between overlapping text labels
force_pull
1
force of attraction between each text label and its data point
direction
"both"
move text labels “both” (default), “x”, or “y” directions
max.time
0.5
maximum number of seconds to try to resolve overlaps
max.iter
10000
maximum number of iterations to try to resolve overlaps
max.overlaps
10
discard text labels that overlap too many other text labels or data
points
nudge_x
0
adjust the starting x position of the text label
nudge_y
0
adjust the starting y position of the text label
box.padding
0.25 lines
padding around the text label
point.padding
0 lines
padding around the labeled data point
arrow
NULL
render line segment as an arrow with grid::arrow()
min.segment.length
0.5
only draw line segments that are longer than 0.5 (default)
Aesthetics
Aesthetics are parameters that can be mapped to your data with
geom_text_repel(mapping = aes(...)).
ggrepel provides the same aesthetics for geom_text_repel
and geom_label_repel that are available in geom_text()
or geom_label(),
but it also provides a few more that are unique to ggrepel.
numeric, negative for left-hand and positive for right-hand curves,
0 for straight lines
segment.angle
90
0-180, less than 90 skews control points toward the start point
segment.ncp
1
number of control points to make a smoother curve
segment.shape
0.5
curve shape by control points approximation/interpolation (1 for
cubic B-spline, -1 for Catmull-Rom spline)
segment.square
TRUE
TRUE to place control points in city-block fashion,
FALSE for oblique placement
segment.squareShape
1
shape of the curve relative to additional control points inserted if
square is TRUE
segment.inflect
FALSE
curve inflection at the midpoint
segment.debug
FALSE
display the curve debug information
Examples
Hide some of the labels
Set labels to the empty string "" to hide them. All data
points repel the non-empty labels.
set.seed(42)
dat2 <- subset(mtcars, wt > 3 & wt < 4)
# Hide all of the text labels.
dat2$car <- ""
# Let's just label these items.
ix_label <- c(2, 3, 14)
dat2$car[ix_label] <- rownames(dat2)[ix_label]
ggplot(dat2, aes(wt, mpg, label = car)) +
geom_text_repel() +
geom_point(color = ifelse(dat2$car == "", "grey50", "red"))
We can quickly repel a few text labels from 10,000 data points in the
example below.
We use max.overlaps = Inf to ensure that no text labels
are discarded, even if a text label overlaps lots of other things
(e.g. other text labels or other data points).
Always show all labels, even when they have too many overlaps
Some text labels will be discarded if they overlap too many other
things (default limit is 10). So, if a text label overlaps 10 other text
labels or data points, then it will be discarded.
We can expect to see a warning if some data points could not be
labeled due to too many overlaps.
Set max.overlaps = Inf to override this behavior and
always show all labels, regardless of whether or not a text label
overlaps too many other things.
Use options(ggrepel.max.overlaps = Inf) to set this
globally for your entire session. The global option can be overridden by
providing the max.overlaps argument to
geom_text_repel().
Set xlim or ylim to Inf or
-Inf to disable repulsion away from the edges of the panel.
Use NA to indicate the edge of the panel.
set.seed(42)
ggplot(dat, aes(wt, mpg, label = car)) +
geom_point(color = "red") +
geom_text_repel(
# Repel away from the left edge, not from the right.
xlim = c(NA, Inf),
# Do not repel from top or bottom edges.
ylim = c(-Inf, Inf)
)
We can also disable clipping to allow the labels to go beyond the
edges of the panel.
Repel labels from data points with different
sizes
We can use the continuous_scale()
function from ggplot2. It allows us to specify a single scale that
applies to multiple aesthetics.
For ggrepel, we want to apply a single size scale to two
aesthetics:
size, which tells ggplot2 the size of the points to
draw on the plot
point.size, which tells ggrepel the point size, so it
can position the text labels away from them
In the example below, there is a third size in the call
to geom_text_repel() to specify the font size for the text
labels.
geom_text_repel()
my_pal <- function(range = c(1, 6)) {
force(range)
function(x) scales::rescale(x, to = range, from = c(0, 1))
}
ggplot(dat, aes(wt, mpg, label = car)) +
geom_point(aes(size = cyl), alpha = 0.6) + # data point size
continuous_scale(
aesthetics = c("size", "point.size"), scale_name = "size",
palette = my_pal(c(2, 15)),
guide = guide_legend(override.aes = list(label = "")) # hide "a" in legend
) +
geom_text_repel(
aes(point.size = cyl), # data point size
size = 5, # font size in the text labels
point.padding = 0, # additional padding around each point
min.segment.length = 0, # draw all line segments
max.time = 1, max.iter = 1e5, # stop after 1 second, or after 100,000 iterations
box.padding = 0.3 # additional padding around each text label
) +
theme(legend.position = "right")
geom_label_repel()
my_pal <- function(range = c(1, 6)) {
force(range)
function(x) scales::rescale(x, to = range, from = c(0, 1))
}
ggplot(dat, aes(wt, mpg, label = car)) +
geom_label_repel(
aes(point.size = cyl), # data point size
size = 5, # font size in the text labels
point.padding = 0, # additional padding around each point
min.segment.length = 0, # draw all line segments
max.time = 1, max.iter = 1e5, # stop after 1 second, or after 100,000 iterations
box.padding = 0.3 # additional padding around each text label
) +
# Put geom_point() after geom_label_repel, so the
# legend for geom_point() appears on the top layer.
geom_point(aes(size = cyl), alpha = 0.6) + # data point size
continuous_scale(
aesthetics = c("size", "point.size"),
scale_name = "size",
palette = my_pal(c(2, 15)),
guide = guide_legend(override.aes = list(label = "")) # hide "a" in legend
) +
theme(legend.position = "right")
Limit labels to a specific area
Use options xlim and ylim to constrain the
labels to a specific area. Limits are specified in data coordinates. Use
NA when there is no lower or upper bound in a particular
direction.
Here we also use grid::arrow() to render the segments as
arrows.
set.seed(42)
# All labels should be to the right of 3.
x_limits <- c(3, NA)
p <- ggplot(dat) +
aes(
x = wt, y = mpg, label = car,
fill = factor(cyl), segment.color = factor(cyl)
) +
geom_vline(xintercept = x_limits, linetype = 3) +
geom_point() +
geom_label_repel(
color = "white",
arrow = arrow(
length = unit(0.03, "npc"), type = "closed", ends = "first"
),
xlim = x_limits,
point.padding = NA,
box.padding = 0.1
) +
scale_fill_discrete(
name = "cyl",
# The same color scall will apply to both of these aesthetics.
aesthetics = c("fill", "segment.color")
)
p
Remove “a” from the legend
Sometimes we want to remove the “a” labels in the legend.
We can do that by overriding the legend aesthetics:
# Don't use "color" in the legend.
p + guides(fill = guide_legend(override.aes = aes(color = NA)))
# Or set the label to the empty string "" (or any other string).
p + guides(fill = guide_legend(override.aes = aes(label = "")))
Align labels on the top or bottom edge
Use hjust to justify the text neatly:
hjust = 0 for left-align
hjust = 0.5 for center
hjust = 1 for right-align
Sometimes the labels do not align perfectly. Try using
direction = "x" to limit label movement to the x-axis (left
and right) or direction = "y" to limit movement to the
y-axis (up and down). The default is
direction = "both".
Also try using xlim() and
ylim()
to increase the size of the plotting area so all of the labels fit
comfortably.
Pedro Aphalo created a great
extension package for ggplot2 called ggpp that provides
useful functions such as position_nudge_center(), which we
demonstrate below:
library(ggpp)
library(patchwork)
## Example data frame where each species' principal components have been computed.
df <- data.frame(
Species = paste("Species", 1:5),
PC1 = c(-4, -3.5, 1, 2, 3),
PC2 = c(-1, -1, 0, -0.5, 0.7)
)
p <- ggplot(df, aes(x = PC1, y = PC2, label = Species)) +
geom_segment(aes(x = 0, y = 0, xend = PC1, yend = PC2),
arrow = arrow(length = unit(0.1, "inches"))) +
xlim(-5, 5) +
ylim(-2, 2) +
geom_hline(aes(yintercept = 0), linewidth = 0.2) +
geom_vline(aes(xintercept = 0), linewidth = 0.2)
p1 <- p + geom_text_repel()
p2 <- p + geom_text_repel(position = position_nudge_center(0.2, 0.1, 0, 0))
p1 + (p2 + labs(title = "position_nudge_center()"))
Label sf objects
Currently if you use geom_text_repel() or
geom_label_repel() with a ggplot2::geom_sf
plot, you will probably get an error like
Error: geom_label_repel requires the following missing aesthetics: x and y
There’s a workaround to this which will enable the
ggrepel functions to work with spatial sf
plots like this - you just need to include:
We can place shadows (or glow) underneath each text label to enhance
the readability of the text. This might be useful when text labels are
placed on top of other plot elements. This feature uses the same code as
the shadowtext
package by Guangchuang
Yu.
set.seed(42)
ggplot(dat, aes(wt, mpg, label = car)) +
geom_point(color = "red") +
geom_text_repel(
color = "white", # text color
bg.color = "grey30", # shadow color
bg.r = 0.15 # shadow radius
)
Verbose timing information
Use verbose = TRUE to see:
how many iterations of the physical simulation were completed
how much time has elapsed, in seconds
how many overlaps remain unresolved in the final figure
# Limit the x-axis to values <= 3
p + scale_x_continuous(limits = c(NA, 3))
# Transform the y-axis with a pseudo log transformation
p + coord_trans(y = scales::pseudo_log_trans(base = 2, sigma = 0.1))
Unicode characters (Japanese)
library(ggrepel)
set.seed(42)
dat <- data.frame(
x = runif(32),
y = runif(32),
label = strsplit(
x = "原文篭毛與美篭母乳布久思毛與美夫君志持此岳尓菜採須兒家吉閑名思毛",
split = ""
)[[1]]
)
# Make sure to choose a font that is installed on your system.
my_font <- "HiraginoSans-W0"
ggplot(dat, aes(x, y, label = label)) +
geom_point(size = 2, color = "red") +
geom_text_repel(size = 8, family = my_font) +
ggtitle("テスト") +
theme_bw(base_size = 18, base_family = my_font)
Mathematical expressions
d <- data.frame(
x = c(1, 2, 2, 1.75, 1.25),
y = c(1, 3, 1, 2.65, 1.25),
math = c(
NA,
"integral(f(x) * dx, a, b)",
NA,
"lim(f(x), x %->% 0)",
NA
)
)
ggplot(d, aes(x, y, label = math)) +
geom_point() +
geom_label_repel(
parse = TRUE, # Parse mathematical expressions.
size = 6,
box.padding = 2
)
Animation
# This chunk of code will take a minute or two to run.
library(ggrepel)
library(animation)
plot_frame <- function(n) {
set.seed(42)
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_text_repel(
size = 5, force = 1, max.iter = n
) +
geom_point(color = "red") +
# theme_minimal(base_size = 16) +
labs(title = n)
print(p)
}
xs <- ceiling(1.18^(1:52))
# xs <- ceiling(1.4^(1:26))
xs <- c(xs, rep(xs[length(xs)], 15))
# plot(xs)
saveGIF(
lapply(xs, function(i) {
plot_frame(i)
}),
interval = 0.15,
ani.width = 800,
ani.heigth = 600,
movie.name = "animated.gif"
)
ggrepel/vignettes/style.css 0000644 0001762 0000144 00000000122 13556321170 015557 0 ustar ligges users .tocify-subheader > .tocify-item {
text-indent: initial;
padding-left: 2em;
}
ggrepel/src/ 0000755 0001762 0000144 00000000000 14667131606 012500 5 ustar ligges users ggrepel/src/RcppExports.cpp 0000644 0001762 0000144 00000015707 14532674424 015510 0 ustar ligges users // Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include
using namespace Rcpp;
#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif
// euclid
double euclid(NumericVector a, NumericVector b);
RcppExport SEXP _ggrepel_euclid(SEXP aSEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type a(aSEXP);
Rcpp::traits::input_parameter< NumericVector >::type b(bSEXP);
rcpp_result_gen = Rcpp::wrap(euclid(a, b));
return rcpp_result_gen;
END_RCPP
}
// centroid
NumericVector centroid(NumericVector b, double hjust, double vjust);
RcppExport SEXP _ggrepel_centroid(SEXP bSEXP, SEXP hjustSEXP, SEXP vjustSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type b(bSEXP);
Rcpp::traits::input_parameter< double >::type hjust(hjustSEXP);
Rcpp::traits::input_parameter< double >::type vjust(vjustSEXP);
rcpp_result_gen = Rcpp::wrap(centroid(b, hjust, vjust));
return rcpp_result_gen;
END_RCPP
}
// intersect_circle_rectangle
bool intersect_circle_rectangle(NumericVector c, NumericVector r);
RcppExport SEXP _ggrepel_intersect_circle_rectangle(SEXP cSEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type c(cSEXP);
Rcpp::traits::input_parameter< NumericVector >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(intersect_circle_rectangle(c, r));
return rcpp_result_gen;
END_RCPP
}
// intersect_line_circle
NumericVector intersect_line_circle(NumericVector p1, NumericVector p2, double r);
RcppExport SEXP _ggrepel_intersect_line_circle(SEXP p1SEXP, SEXP p2SEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type p1(p1SEXP);
Rcpp::traits::input_parameter< NumericVector >::type p2(p2SEXP);
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(intersect_line_circle(p1, p2, r));
return rcpp_result_gen;
END_RCPP
}
// intersect_line_rectangle
NumericVector intersect_line_rectangle(NumericVector p1, NumericVector p2, NumericVector b);
RcppExport SEXP _ggrepel_intersect_line_rectangle(SEXP p1SEXP, SEXP p2SEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type p1(p1SEXP);
Rcpp::traits::input_parameter< NumericVector >::type p2(p2SEXP);
Rcpp::traits::input_parameter< NumericVector >::type b(bSEXP);
rcpp_result_gen = Rcpp::wrap(intersect_line_rectangle(p1, p2, b));
return rcpp_result_gen;
END_RCPP
}
// select_line_connection
NumericVector select_line_connection(NumericVector p1, NumericVector b);
RcppExport SEXP _ggrepel_select_line_connection(SEXP p1SEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type p1(p1SEXP);
Rcpp::traits::input_parameter< NumericVector >::type b(bSEXP);
rcpp_result_gen = Rcpp::wrap(select_line_connection(p1, b));
return rcpp_result_gen;
END_RCPP
}
// approximately_equal
bool approximately_equal(double x1, double x2);
RcppExport SEXP _ggrepel_approximately_equal(SEXP x1SEXP, SEXP x2SEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< double >::type x1(x1SEXP);
Rcpp::traits::input_parameter< double >::type x2(x2SEXP);
rcpp_result_gen = Rcpp::wrap(approximately_equal(x1, x2));
return rcpp_result_gen;
END_RCPP
}
// repel_boxes2
DataFrame repel_boxes2(NumericMatrix data_points, NumericVector point_size, double point_padding_x, double point_padding_y, NumericMatrix boxes, NumericVector xlim, NumericVector ylim, NumericVector hjust, NumericVector vjust, double force_push, double force_pull, double max_time, double max_overlaps, int max_iter, std::string direction, int verbose);
RcppExport SEXP _ggrepel_repel_boxes2(SEXP data_pointsSEXP, SEXP point_sizeSEXP, SEXP point_padding_xSEXP, SEXP point_padding_ySEXP, SEXP boxesSEXP, SEXP xlimSEXP, SEXP ylimSEXP, SEXP hjustSEXP, SEXP vjustSEXP, SEXP force_pushSEXP, SEXP force_pullSEXP, SEXP max_timeSEXP, SEXP max_overlapsSEXP, SEXP max_iterSEXP, SEXP directionSEXP, SEXP verboseSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type data_points(data_pointsSEXP);
Rcpp::traits::input_parameter< NumericVector >::type point_size(point_sizeSEXP);
Rcpp::traits::input_parameter< double >::type point_padding_x(point_padding_xSEXP);
Rcpp::traits::input_parameter< double >::type point_padding_y(point_padding_ySEXP);
Rcpp::traits::input_parameter< NumericMatrix >::type boxes(boxesSEXP);
Rcpp::traits::input_parameter< NumericVector >::type xlim(xlimSEXP);
Rcpp::traits::input_parameter< NumericVector >::type ylim(ylimSEXP);
Rcpp::traits::input_parameter< NumericVector >::type hjust(hjustSEXP);
Rcpp::traits::input_parameter< NumericVector >::type vjust(vjustSEXP);
Rcpp::traits::input_parameter< double >::type force_push(force_pushSEXP);
Rcpp::traits::input_parameter< double >::type force_pull(force_pullSEXP);
Rcpp::traits::input_parameter< double >::type max_time(max_timeSEXP);
Rcpp::traits::input_parameter< double >::type max_overlaps(max_overlapsSEXP);
Rcpp::traits::input_parameter< int >::type max_iter(max_iterSEXP);
Rcpp::traits::input_parameter< std::string >::type direction(directionSEXP);
Rcpp::traits::input_parameter< int >::type verbose(verboseSEXP);
rcpp_result_gen = Rcpp::wrap(repel_boxes2(data_points, point_size, point_padding_x, point_padding_y, boxes, xlim, ylim, hjust, vjust, force_push, force_pull, max_time, max_overlaps, max_iter, direction, verbose));
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_ggrepel_euclid", (DL_FUNC) &_ggrepel_euclid, 2},
{"_ggrepel_centroid", (DL_FUNC) &_ggrepel_centroid, 3},
{"_ggrepel_intersect_circle_rectangle", (DL_FUNC) &_ggrepel_intersect_circle_rectangle, 2},
{"_ggrepel_intersect_line_circle", (DL_FUNC) &_ggrepel_intersect_line_circle, 3},
{"_ggrepel_intersect_line_rectangle", (DL_FUNC) &_ggrepel_intersect_line_rectangle, 3},
{"_ggrepel_select_line_connection", (DL_FUNC) &_ggrepel_select_line_connection, 2},
{"_ggrepel_approximately_equal", (DL_FUNC) &_ggrepel_approximately_equal, 2},
{"_ggrepel_repel_boxes2", (DL_FUNC) &_ggrepel_repel_boxes2, 16},
{NULL, NULL, 0}
};
RcppExport void R_init_ggrepel(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
ggrepel/src/repel_boxes.cpp 0000644 0001762 0000144 00000066026 14562223600 015513 0 ustar ligges users #include
#ifdef __EMSCRIPTEN__
#define __linux
#include
#undef __linux
#else
#include
#endif
#include
using namespace Rcpp;
// Exported convenience functions ---------------------------------------------
//' Euclidean distance between two points.
//' @param a A numeric vector.
//' @param b A numeric vector.
//' @return The distance between two points.
//' @noRd
// [[Rcpp::export]]
double euclid(NumericVector a, NumericVector b) {
return sqrt(
(a[0] - b[0]) * (a[0] - b[0]) +
(a[1] - b[1]) * (a[1] - b[1])
);
}
//' Get the coordinates of the center of a box.
//' @param b A box like \code{c(x1, y1, x2, y2)}
//' @noRd
// [[Rcpp::export]]
NumericVector centroid(NumericVector b, double hjust, double vjust) {
return NumericVector::create(b[0] + (b[2] - b[0]) * hjust, b[1] + (b[3] - b[1]) * vjust);
}
//' Find the intersections between a line and a rectangle.
//' @param c A circle like \code{c(x, y, r)}
//' @param r A rectangle like \code{c(x1, y1, x2, y2)}
//' @noRd
// [[Rcpp::export]]
bool intersect_circle_rectangle(NumericVector c, NumericVector r) {
// Center of the circle.
double c_x = c[0];
double c_radius = c[2];
// Center of the rectangle.
double r_x = (r[2] + r[0]) / 2;
double r_halfwidth = std::abs(r[0] - r_x);
// Distance between centers.
double cx = std::abs(c_x - r_x);
double xDist = r_halfwidth + c_radius;
if (cx > xDist) {
return false;
}
// Center of the circle.
double c_y = c[1];
// Center of the rectangle.
double r_y = (r[3] + r[1]) / 2;
double r_halfheight = std::abs(r[1] - r_y);
// Distance between centers.
double cy = std::abs(c_y - r_y);
double yDist = r_halfheight + c_radius;
if (cy > yDist) {
return false;
}
if (cx <= r_halfwidth || cy <= r_halfheight)
return true;
double xCornerDist = cx - r_halfwidth;
double yCornerDist = cy - r_halfheight;
double xCornerDistSq = xCornerDist * xCornerDist;
double yCornerDistSq = yCornerDist * yCornerDist;
double maxCornerDistSq = c_radius * c_radius;
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
}
//' Find the intersection between a line and a circle.
//' @param p1 A point on the line like \code{c(x, y)}
//' @param p2 A point at the circle's center
//' @param r The circle's radius
//' @noRd
// [[Rcpp::export]]
NumericVector intersect_line_circle(
NumericVector p1, NumericVector p2, double r
) {
// 0 = x, 1 = y
double theta = std::atan2(p1[1] - p2[1], p1[0] - p2[0]);
return NumericVector::create(
p2[0] + r * std::cos(theta),
p2[1] + r * std::sin(theta)
);
}
//' Find the intersections between a line and a rectangle.
//' @param p1 A point like \code{c(x, y)}
//' @param p2 A point like \code{c(x, y)}
//' @param b A rectangle like \code{c(x1, y1, x2, y2)}
//' @noRd
// [[Rcpp::export]]
NumericVector intersect_line_rectangle(
NumericVector p1, NumericVector p2, NumericVector b
) {
// Sorry for the ugly code :(
double dy = p2[1] - p1[1];
double dx = p2[0] - p1[0];
double slope = dy / dx;
double intercept = p2[1] - p2[0] * slope;
NumericMatrix retval(4, 2);
std::fill(retval.begin(), retval.end(), -INFINITY);
double x, y;
// +----------+ < b[3]
// | |
// | | < y
// | |
// +----------+ < b[1]
// ^ ^ ^
// b[0] x b[2]
if (dx != 0) {
// Left boundary
x = b[0];
y = dy == 0 ? p1[1] : slope * x + intercept;
if (b[1] <= y && y <= b[3]) {
retval(0, _) = NumericVector::create(x, y);
}
// Right boundary
x = b[2];
y = dy == 0 ? p1[1] : slope * x + intercept;
if (b[1] <= y && y <= b[3]) {
retval(1, _) = NumericVector::create(x, y);
}
}
if (dy != 0) {
// Bottom boundary
y = b[1];
x = dx == 0 ? p1[0] : (y - intercept) / slope;
if (b[0] <= x && x <= b[2]) {
retval(2, _) = NumericVector::create(x, y);
}
// Top boundary
y = b[3];
x = dx == 0 ? p1[0] : (y - intercept) / slope;
if (b[0] <= x && x <= b[2]) {
retval(3, _) = NumericVector::create(x, y);
}
}
int i = 0;
int imin = 0;
double d;
double dmin = INFINITY;
for (i = 0; i < 4; i++) {
d = euclid(retval(i, _), p1);
if (d < dmin) {
dmin = d;
imin = i;
}
}
return retval(imin, _);
}
// [[Rcpp::export]]
NumericVector select_line_connection(
NumericVector p1, NumericVector b
) {
NumericVector out(2);
// Find shortest path
// +----------+ < b[3]
// | |
// | |
// | |
// +----------+ < b[1]
// ^ ^
// b[0] b[2]
bool top = false;
bool left = false;
bool right = false;
bool bottom = false;
if ((p1[0] >= b[0]) && (p1[0] <= b[2])) {
out[0] = p1[0];
} else if (p1[0] > b[2]) {
out[0] = b[2];
right = true;
} else{
out[0] = b[0];
left = true;
}
if ((p1[1] >= b[1]) && (p1[1] <= b[3])) {
out[1] = p1[1];
} else if (p1[1] > b[3]) {
out[1] = b[3];
top = true;
} else{
out[1] = b[1];
bottom = true;
}
// Nudge to center
double midx = (b[0] + b[2]) * 0.5;
double midy = (b[3] + b[1]) * 0.5;
double d = std::sqrt(
std::pow(p1[0] - out[0], 2) +
std::pow(p1[1] - out[1], 2)
);
if ((top || bottom) && !(left || right)) {
// top or bottom
double altd = std::sqrt(
std::pow(p1[0] - midx, 2) +
std::pow(p1[1] - out[1], 2)
);
out[0] = out[0] + (midx - out[0]) * d / altd;
} else if ((left || right) && !(top || bottom)) {
// left or right
double altd = std::sqrt(
std::pow(p1[0] - out[0], 2) +
std::pow(p1[1] - midy, 2)
);
out[1] = out[1] + (midy - out[1]) * d / altd;
} else if ((left || right) && (top || bottom)) {
double altd1 = std::sqrt(
std::pow(p1[0] - midx, 2) +
std::pow(p1[1] - out[1], 2)
);
double altd2 = std::sqrt(
std::pow(p1[0] - out[0], 2) +
std::pow(p1[1] - midy, 2)
);
if (altd1 < altd2) {
out[0] = out[0] + (midx - out[0]) * d / altd1;
} else {
out[1] = out[1] + (midy - out[1]) * d / altd2;
}
}
return out;
}
// Main code for text label placement -----------------------------------------
typedef struct {
double x, y;
} Point;
Point operator -(const Point& a, const Point& b) {
Point p = {a.x - b.x, a.y - b.y};
return p;
}
Point operator +(const Point& a, const Point& b) {
Point p = {a.x + b.x, a.y + b.y};
return p;
}
Point operator /(const Point& a, const double& b) {
Point p = {a.x / b, a.y / b};
return p;
}
Point operator *(const double& b, const Point& a) {
Point p = {a.x * b, a.y * b};
return p;
}
Point operator *(const Point& a, const double& b) {
Point p = {a.x * b, a.y * b};
return p;
}
typedef struct {
double x1, y1, x2, y2;
} Box;
Box operator +(const Box& b, const Point& p) {
Box c = {b.x1 + p.x, b.y1 + p.y, b.x2 + p.x, b.y2 + p.y};
return c;
}
typedef struct {
double x, y, r;
} Circle;
Circle operator +(const Circle& b, const Point& p) {
Circle c = {b.x + p.x, b.y + p.y, b.r};
return c;
}
//' Euclidean distance between two points.
//' @param a A point.
//' @param b A point.
//' @return The distance between two points.
//' @noRd
double euclid(Point a, Point b) {
Point dist = a - b;
return sqrt(dist.x * dist.x + dist.y * dist.y);
}
//' Squared Euclidean distance between two points.
//' @param a A point.
//' @param b A point.
//' @return The distance between two points.
//' @noRd
double euclid2(Point a, Point b) {
Point dist = a - b;
return dist.x * dist.x + dist.y * dist.y;
}
// [[Rcpp::export]]
bool approximately_equal(double x1, double x2) {
return std::abs(x2 - x1) < (std::numeric_limits::epsilon() * 100);
}
bool line_intersect(Point p1, Point q1, Point p2, Point q2) {
// Special exception, where q1 and q2 are equal (do intersect)
if (q1.x == q2.x && q1.y == q2.y)
return false;
// If line is point
if (p1.x == q1.x && p1.y == q1.y)
return false;
if (p2.x == q2.x && p2.y == q2.y)
return false;
double dy1 = q1.y - p1.y;
double dx1 = q1.x - p1.x;
double slope1 = dy1 / dx1;
double intercept1 = q1.y - q1.x * slope1;
double dy2 = q2.y - p2.y;
double dx2 = q2.x - p2.x;
double slope2 = dy2 / dx2;
double intercept2 = q2.y - q2.x * slope2;
double x,y;
// check if lines vertical
if (approximately_equal(dx1,0.0)) {
if (approximately_equal(dx2,0.0)) {
return false;
} else {
x = p1.x;
y = slope2 * x + intercept2;
}
} else if (approximately_equal(dx2,0.0)) {
x = p2.x;
y = slope1 * x + intercept1;
} else {
if (approximately_equal(slope1,slope2)) {
return false;
}
x = (intercept2 - intercept1) / (slope1 - slope2);
y = slope1 * x + intercept1;
}
if (x < p1.x && x < q1.x) {
return false;
} else if (x > p1.x && x > q1.x) {
return false;
} else if (y < p1.y && y < q1.y) {
return false;
} else if (y > p1.y && y > q1.y) {
return false;
} else if (x < p2.x && x < q2.x) {
return false;
} else if (x > p2.x && x > q2.x) {
return false;
} else if (y < p2.y && y < q2.y) {
return false;
} else if (y > p2.y && y > q2.y) {
return false;
} else{
return true;
}
}
//' Move a box into the area specificied by x limits and y limits.
//' @param b A box like \code{c(x1, y1, x2, y2)}
//' @param xlim A Point with limits on the x axis like \code{c(xmin, xmax)}
//' @param ylim A Point with limits on the y axis like \code{c(xmin, xmax)}
//' @param force Magnitude of the force (defaults to \code{1e-6})
//' @noRd
Box put_within_bounds(Box b, Point xlim, Point ylim, double force = 1e-5) {
//double d;
//if (b.x1 < xlim.x) {
// d = std::max(fabs(b.x1 - xlim.x), 0.02);
// b.x1 += force / pow(d, 2);
// b.x2 += force / pow(d, 2);
//} else if (b.x2 > xlim.y) {
// d = std::max(fabs(b.x2 - xlim.y), 0.02);
// b.x1 -= force / pow(d, 2);
// b.x2 -= force / pow(d, 2);
//}
//if (b.y1 < ylim.x) {
// d = std::max(fabs(b.y1 - ylim.x), 0.02);
// b.y1 += force / pow(d, 2);
// b.y2 += force / pow(d, 2);
//} else if (b.y2 > ylim.y) {
// d = std::max(fabs(b.y2 - ylim.y), 0.02);
// b.y1 -= force / pow(d, 2);
// b.y2 -= force / pow(d, 2);
//}
double width = fabs(b.x1 - b.x2);
double height = fabs(b.y1 - b.y2);
if (b.x1 < xlim.x) {
b.x1 = xlim.x;
b.x2 = b.x1 + width;
} else if (b.x2 > xlim.y) {
b.x2 = xlim.y;
b.x1 = b.x2 - width;
}
if (b.y1 < ylim.x) {
b.y1 = ylim.x;
b.y2 = b.y1 + height;
} else if (b.y2 > ylim.y) {
b.y2 = ylim.y;
b.y1 = b.y2 - height;
}
return b;
}
//' Get the coordinates of the center of a box.
//' @param b A box like \code{c(x1, y1, x2, y2)}
//' @noRd
Point centroid(Box b, double hjust, double vjust) {
Point p = {(b.x1 + (b.x2 - b.x1) * hjust), b.y1 + (b.y2 - b.y1) * vjust};
return p;
}
//' Test if a box overlaps another box.
//' @param a A box like \code{c(x1, y1, x2, y2)}
//' @param b A box like \code{c(x1, y1, x2, y2)}
//' @noRd
bool overlaps(Box a, Box b) {
return
b.x1 <= a.x2 &&
b.y1 <= a.y2 &&
b.x2 >= a.x1 &&
b.y2 >= a.y1;
}
//' Test if a box overlaps another box.
//' @param a A box like \code{c(x1, y1, x2, y2)}
//' @param b A box like \code{c(x1, y1, x2, y2)}
//' @noRd
bool overlaps(Circle c, Box r) {
// Center of the circle.
double c_x = c.x;
double c_radius = c.r;
// Center of the rectangle.
double r_x = (r.x1 + r.x2) / 2;
double r_halfwidth = std::abs(r.x1 - r_x);
// Distance between centers.
double cx = std::abs(c_x - r_x);
double xDist = r_halfwidth + c_radius;
if (cx > xDist) {
return false;
}
// Center of the circle.
double c_y = c.y;
// Center of the rectangle.
double r_y = (r.y1 + r.y2) / 2;
double r_halfheight = std::abs(r.y1 - r_y);
// Distance between centers.
double cy = std::abs(c_y - r_y);
double yDist = r_halfheight + c_radius;
if (cy > yDist) {
return false;
}
if (cx <= r_halfwidth || cy <= r_halfheight) {
return true;
}
double xCornerDist = cx - r_halfwidth;
double yCornerDist = cy - r_halfheight;
double xCornerDistSq = xCornerDist * xCornerDist;
double yCornerDistSq = yCornerDist * yCornerDist;
double maxCornerDistSq = c_radius * c_radius;
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
}
Point repel_force_both(
Point a, Point b, double force = 0.000001
) {
double dx = fabs(a.x - b.x);
double dy = fabs(a.y - b.y);
// Constrain the minimum distance, so it is never 0.
double d2 = std::max(dx * dx + dy * dy, 0.0004);
// Compute a unit vector in the direction of the force.
Point v = (a - b) / sqrt(d2);
// Divide the force by the squared distance.
Point f = force * v / d2;
if (dx > dy) {
// f.y = f.y * dx / dy;
f.y = f.y * 2;
} else {
// f.x = f.x * dy / dx;
f.x = f.x * 2;
}
return f;
}
Point repel_force_y(
Point a, Point b, double force = 0.000001
) {
double dx = fabs(a.x - b.x);
double dy = fabs(a.y - b.y);
// Constrain the minimum distance, so it is never 0.
double d2 = std::max(dx * dx + dy * dy, 0.0004);
// Compute a unit vector in the direction of the force.
Point v = {0,1};
if (a.y < b.y) {
v.y = -1;
}
// Divide the force by the distance.
Point f = force * v / d2 * 2;
return f;
}
Point repel_force_x(
Point a, Point b, double force = 0.000001
) {
double dx = fabs(a.x - b.x);
double dy = fabs(a.y - b.y);
// Constrain the minimum distance, so it is never 0.
double d2 = std::max(dx * dx + dy * dy, 0.0004);
// Compute a unit vector in the direction of the force.
Point v = {1,0};
if (a.x < b.x) {
v.x = -1;
}
// Divide the force by the squared distance.
Point f = force * v / d2 * 2;
return f;
}
//' Compute the repulsion force upon point \code{a} from point \code{b}.
//'
//' The force decays with the squared distance between the points, similar
//' to the force of repulsion between magnets.
//'
//' @param a A point like \code{c(x, y)}
//' @param b A point like \code{c(x, y)}
//' @param force Magnitude of the force (defaults to \code{1e-6})
//' @param direction direction in which to exert force, either "both", "x", or "y"
//' @noRd
Point repel_force(
Point a, Point b, double force = 0.000001, std::string direction = "both"
) {
Point out;
if (direction == "x") {
out = repel_force_x(a, b, force);
} else if (direction == "y") {
out = repel_force_y(a, b, force);
} else{
out = repel_force_both(a, b, force);
}
return out;
}
Point spring_force_both(
Point a, Point b, double force = 0.000001
) {
Point f = {0, 0};
Point v = (a - b) ;
f = force * v;
return f;
}
Point spring_force_y(
Point a, Point b, double force = 0.000001
) {
Point f = {0, 0};
Point v = {0, (a.y - b.y)};
f = force * v;
return f;
}
Point spring_force_x(
Point a, Point b, double force = 0.000001
) {
Point f = {0, 0};
Point v = {(a.x - b.x), 0};
f = force * v ;
return f;
}
//' Compute the spring force upon point \code{a} from point \code{b}.
//'
//' The force increases with the distance between the points, similar
//' to Hooke's law for springs.
//'
//' @param a A point like \code{c(x, y)}
//' @param b A point like \code{c(x, y)}
//' @param force Magnitude of the force (defaults to \code{1e-6})
//' @param direction direction in which to exert force, either "both", "x", or "y"
//' @noRd
Point spring_force(
Point a, Point b, double force = 0.000001, std::string direction = "both"
) {
Point out;
if (direction == "x") {
out = spring_force_x(a, b, force);
} else if (direction == "y") {
out = spring_force_y(a, b, force);
} else{
out = spring_force_both(a, b, force);
}
return out;
}
std::vector rescale(std::vector v) {
double min_value = *std::min_element(v.begin(), v.end());
double max_value = *std::max_element(v.begin(), v.end());
for (long unsigned int i = 0; i < v.size(); i++) {
v[i] = (v[i] - min_value) / max_value;
}
return v;
}
//' Adjust the layout of a list of potentially overlapping boxes.
//' @param data_points A numeric matrix with rows representing points like
//' \code{rbind(c(x, y), c(x, y), ...)}
//' @param point_size A numeric vector representing the sizes of data points.
//' @param point_padding_x Padding around each data point on the x axis.
//' @param point_padding_y Padding around each data point on the y axis.
//' @param boxes A numeric matrix with rows representing boxes like
//' \code{rbind(c(x1, y1, x2, y2), c(x1, y1, x2, y2), ...)}
//' @param xlim A numeric vector representing the limits on the x axis like
//' \code{c(xmin, xmax)}
//' @param ylim A numeric vector representing the limits on the y axis like
//' \code{c(ymin, ymax)}
//' @param force Magnitude of the force (defaults to \code{1e-6})
//' @param max_time Maximum number of seconds to try to resolve overlaps
//' (defaults to 0.1)
//' @param max_iter Maximum number of iterations to try to resolve overlaps
//' (defaults to 2000)
//' @noRd
// [[Rcpp::export]]
DataFrame repel_boxes2(
NumericMatrix data_points,
NumericVector point_size,
double point_padding_x, double point_padding_y,
NumericMatrix boxes,
NumericVector xlim, NumericVector ylim,
NumericVector hjust, NumericVector vjust,
double force_push = 1e-7,
double force_pull = 1e-7,
double max_time = 0.1,
double max_overlaps = 10,
int max_iter = 2000,
std::string direction = "both",
int verbose = 0
) {
int n_points = data_points.nrow();
int n_texts = boxes.nrow();
// Larger data points push text away with greater force.
double force_point_size = 100.0;
if (NumericVector::is_na(force_push)) {
force_push = 1e-6;
}
if (NumericVector::is_na(force_pull)) {
force_pull = 1e-6;
}
if (force_push == 0) {
max_iter = 0;
}
// Try to catch errors.
if (n_texts > n_points) {
Rcerr << "n_texts is " << n_texts << std::endl;
Rcerr << "n_points is " << n_points << std::endl;
stop("n_texts > n_points");
}
if (point_size.length() != n_points) {
Rcerr << "point_size.length() is " << point_size.length() << std::endl;
Rcerr << "n_points is " << n_points << std::endl;
stop("point_size.length() != n_points");
}
if (hjust.length() < n_texts) {
Rcerr << "hjust.length() is " << hjust.length() << std::endl;
Rcerr << "n_texts is " << n_texts << std::endl;
stop("hjust.length() < n_texts");
}
if (vjust.length() < n_texts) {
Rcerr << "vjust.length() is " << vjust.length() << std::endl;
Rcerr << "n_texts is " << n_texts << std::endl;
stop("vjust.length() < n_texts");
}
if (xlim.length() != 2) {
Rcerr << "xlim.length() is " << xlim.length() << std::endl;
stop("xlim.length() != 2");
}
if (ylim.length() != 2) {
Rcerr << "ylim.length() is " << ylim.length() << std::endl;
stop("ylim.length() != 2");
}
Point xbounds, ybounds;
xbounds.x = xlim[0];
xbounds.y = xlim[1];
ybounds.x = ylim[0];
ybounds.y = ylim[1];
// Each data point gets a bounding circle.
std::vector Points(n_points);
std::vector DataCircles(n_points);
for (int i = 0; i < n_points; i++) {
DataCircles[i].x = data_points(i, 0);
DataCircles[i].y = data_points(i, 1);
DataCircles[i].r = point_size[i] + (point_padding_x + point_padding_y) / 4.0;
Points[i].x = data_points(i, 0);
Points[i].y = data_points(i, 1);
}
// Add a tiny bit of jitter to each text box at the start.
NumericVector r = rnorm(n_texts, 0, force_push);
std::vector TextBoxes(n_texts);
std::vector original_centroids(n_texts);
std::vector TextBoxWidths(n_texts, 0);
for (int i = 0; i < n_texts; i++) {
TextBoxes[i].x1 = boxes(i, 0);
TextBoxes[i].x2 = boxes(i, 2);
TextBoxes[i].y1 = boxes(i, 1);
TextBoxes[i].y2 = boxes(i, 3);
TextBoxWidths[i] = std::abs(TextBoxes[i].x2 - TextBoxes[i].x1);
// Don't add jitter if the user wants to repel in just one direction.
if (direction != "y") {
TextBoxes[i].x1 += r[i];
TextBoxes[i].x2 += r[i];
}
if (direction != "x") {
TextBoxes[i].y1 += r[i];
TextBoxes[i].y2 += r[i];
}
original_centroids[i] = centroid(TextBoxes[i], hjust[i], vjust[i]);
}
// Rescale to be in the range [0,1]
TextBoxWidths = rescale(TextBoxWidths);
// for (int i = 0; i < n_texts; i++) {
// Rcout << "[" << i << "] = " << TextBoxWidths[i] << "; ";
// }
// Rcout << std::endl;
// Initialize velocities to zero
std::vector velocities(n_texts);
for (int i = 0; i < n_texts; i++) {
Point v = {0,0};
velocities[i] = v;
}
double velocity_decay = 0.7;
Point f, ci, cj;
//Timer timer;
//timer.step("start");
nanotime_t start_time = get_nanotime();
nanotime_t elapsed_time = 0;
// convert to nanoseconds
max_time *= 1e9;
std::vector total_overlaps(n_texts, 0);
std::vector too_many_overlaps(n_texts, false);
int iter = 0;
int n_overlaps = 1;
int p_overlaps = 1;
bool i_overlaps = true;
while (n_overlaps && iter < max_iter) {
iter += 1;
p_overlaps = n_overlaps;
n_overlaps = 0;
// Maximum time limit.
if (iter % 10 == 0) {
elapsed_time = get_nanotime() - start_time;
// Stop trying to layout the text after some time.
if (elapsed_time > max_time) {
break;
}
}
// The forces get weaker over time.
force_push *= 0.99999;
force_pull *= 0.9999;
// velocity_decay *= 0.999;
for (int i = 0; i < n_texts; i++) {
if (iter == 2 && total_overlaps[i] > max_overlaps) {
too_many_overlaps[i] = true;
}
// if (iter == 2) {
// // for (int i = 0; i < n_texts; i++) {
// Rcout << "total_overlaps[" << i << "] = " << total_overlaps[i] << "; ";
// // }
// Rcout << std::endl;
// }
if (too_many_overlaps[i]) {
continue;
}
// Reset overlaps for the next iteration
total_overlaps[i] = 0;
i_overlaps = false;
f.x = 0;
f.y = 0;
ci = centroid(TextBoxes[i], hjust[i], vjust[i]);
for (int j = 0; j < n_points; j++) {
if (i == j) {
// Skip the data points if the size and padding is 0.
if (point_size[i] == 0 && point_padding_x == 0 && point_padding_y == 0) {
continue;
}
// Repel the box from its data point.
if (overlaps(DataCircles[i], TextBoxes[i])) {
n_overlaps += 1;
i_overlaps = true;
total_overlaps[i] += 1;
f = f + repel_force(
ci, Points[i],
// force_push,
point_size[i] * force_point_size * force_push,
direction
);
}
} else if (j < n_texts && too_many_overlaps[j]) {
// Skip the data points if the size and padding is 0.
if (point_size[j] == 0 && point_padding_x == 0 && point_padding_y == 0) {
continue;
}
// Repel the box from other data points.
if (overlaps(DataCircles[j], TextBoxes[i])) {
n_overlaps += 1;
i_overlaps = true;
total_overlaps[i] += 1;
f = f + repel_force(
ci, Points[j],
// force_push,
point_size[i] * force_point_size * force_push,
direction
);
}
} else {
if (j < n_texts) {
cj = centroid(TextBoxes[j], hjust[j], vjust[j]);
// Repel the box from overlapping boxes.
if (overlaps(TextBoxes[i], TextBoxes[j])) {
n_overlaps += 1;
i_overlaps = true;
total_overlaps[i] += 1;
f = f + repel_force(ci, cj, force_push, direction);
}
}
// Skip the data points if the size and padding is 0.
if (point_size[j] == 0 && point_padding_x == 0 && point_padding_y == 0) {
continue;
}
// Repel the box from other data points.
if (overlaps(DataCircles[j], TextBoxes[i])) {
n_overlaps += 1;
i_overlaps = true;
total_overlaps[i] += 1;
f = f + repel_force(
ci, Points[j],
// force_push,
point_size[i] * force_point_size * force_push,
direction
);
}
}
}
// Pull the box toward its original position.
if (!i_overlaps) {
// force_pull *= 0.999;
f = f + spring_force(
original_centroids[i], ci, force_pull, direction);
}
double overlap_multiplier = 1.0;
if (total_overlaps[i] > 10) {
overlap_multiplier += 0.5;
} else {
overlap_multiplier += 0.05 * total_overlaps[i];
}
velocities[i] = overlap_multiplier * velocities[i] * (TextBoxWidths[i] + 1e-6) * velocity_decay + f;
// velocities[i] = velocities[i] * velocity_decay + f;
TextBoxes[i] = TextBoxes[i] + velocities[i];
// Put boxes within bounds
TextBoxes[i] = put_within_bounds(TextBoxes[i], xbounds, ybounds);
// look for line clashes
if (n_overlaps == 0 || iter % 5 == 0) {
for (int j = 0; j < n_texts; j++) {
cj = centroid(TextBoxes[j], hjust[j], vjust[j]);
ci = centroid(TextBoxes[i], hjust[i], vjust[i]);
// Switch label positions if lines overlap
if (
i != j && line_intersect(ci, Points[i], cj, Points[j])
) {
n_overlaps += 1;
TextBoxes[i] = TextBoxes[i] + spring_force(cj, ci, 1, direction);
TextBoxes[j] = TextBoxes[j] + spring_force(ci, cj, 1, direction);
// Check if resolved
ci = centroid(TextBoxes[i], hjust[i], vjust[i]);
cj = centroid(TextBoxes[j], hjust[j], vjust[j]);
if (line_intersect(ci, Points[i], cj, Points[j])) {
//Rcout << "unresolved overlap in iter " << iter << std::endl;
TextBoxes[i] = TextBoxes[i] +
spring_force(cj, ci, 1.25, direction);
TextBoxes[j] = TextBoxes[j] +
spring_force(ci, cj, 1.25, direction);
}
}
}
}
} // loop through all text labels
} // while any overlaps exist and we haven't reached max iterations
if (verbose) {
if (elapsed_time > max_time) {
Rprintf(
"%.2fs elapsed for %d iterations, %d overlaps. Consider increasing 'max.time'.\n",
max_time / 1e9, iter, p_overlaps
);
} else if (iter >= max_iter) {
Rprintf(
"%d iterations in %.2fs, %d overlaps. Consider increasing 'max.iter'.\n",
max_iter, elapsed_time / 1e9, p_overlaps
);
} else {
Rprintf(
"text repel complete in %d iterations (%.2fs), %d overlaps\n",
iter, elapsed_time / 1e9, p_overlaps
);
}
}
//timer.step("end");
//NumericVector res(timer);
//for (int i = 0; i < res.size(); i++) {
// res[i] = res[i] / 1000000;
//}
//Rcpp::Rcout << round(res[1] - res[0]) << " ms" << std::endl;
NumericVector xs(n_texts);
NumericVector ys(n_texts);
for (int i = 0; i < n_texts; i++) {
xs[i] = (TextBoxes[i].x1 + TextBoxes[i].x2) / 2;
ys[i] = (TextBoxes[i].y1 + TextBoxes[i].y2) / 2;
}
return Rcpp::DataFrame::create(
Rcpp::Named("x") = xs,
Rcpp::Named("y") = ys,
Rcpp::Named("too_many_overlaps") = too_many_overlaps
);
}
ggrepel/NAMESPACE 0000644 0001762 0000144 00000001731 14561740437 013133 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(makeContent,labelrepeltree)
S3method(makeContent,textrepeltree)
export(GeomLabelRepel)
export(GeomTextRepel)
export(PositionNudgeRepel)
export(geom_label_repel)
export(geom_text_repel)
export(position_nudge_repel)
import(Rcpp)
import(ggplot2)
importFrom(grid,convertHeight)
importFrom(grid,convertWidth)
importFrom(grid,curveGrob)
importFrom(grid,gList)
importFrom(grid,gTree)
importFrom(grid,gpar)
importFrom(grid,grobHeight)
importFrom(grid,grobName)
importFrom(grid,grobTree)
importFrom(grid,grobWidth)
importFrom(grid,grobX)
importFrom(grid,grobY)
importFrom(grid,is.grob)
importFrom(grid,is.unit)
importFrom(grid,makeContent)
importFrom(grid,resolveHJust)
importFrom(grid,resolveVJust)
importFrom(grid,roundrectGrob)
importFrom(grid,segmentsGrob)
importFrom(grid,setChildren)
importFrom(grid,stringHeight)
importFrom(grid,stringWidth)
importFrom(grid,textGrob)
importFrom(grid,unit)
importFrom(rlang,warn)
useDynLib(ggrepel)
ggrepel/LICENSE 0000644 0001762 0000144 00000104505 13412707236 012716 0 ustar ligges users GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
ggrepel/NEWS.md 0000644 0001762 0000144 00000041056 14666631705 013021 0 ustar ligges users ggrepel 0.9.6
========================
## Changes
- Remove `exclude_outside()` from `geom_text_repel()` and `geom_label_repel()` because this change introduced too many breaking changes for other users. See issues:
- https://github.com/slowkow/ggrepel/issues/253
- https://github.com/slowkow/ggrepel/issues/255
- https://github.com/slowkow/ggrepel/issues/257
- https://github.com/slowkow/ggrepel/issues/260
- https://github.com/slowkow/ggrepel/issues/261
ggrepel 0.9.5
========================
## Changes
- Introduce a new function `exclude_outside()` into `geom_text_repel()` and `geom_label_repel()` to discard labels outside the panel range, in order to support the [ggbreak] package. See [issue 244] for details.
- Change `expect_equal()` to include a tolerance, to satisfy CRAN testing.
- Delete note about old (before 2.2.1) versions of ggplot2, thanks to @olivroy for [pull request 246].
- Add website link to `DESCRIPTION`, thanks to @olivroy for [pull request 241].
[ggbreak]: https://github.com/YuLab-SMU/ggbreak
[issue 244]: https://github.com/slowkow/ggrepel/issues/244
[pull request 241]: https://github.com/slowkow/ggrepel/pull/241
[pull request 246]: https://github.com/slowkow/ggrepel/pull/246
ggrepel 0.9.4
========================
## Changes
* Add `min.segment.length` to the options table in the examples page, thanks to
@jwhendy for [mentioning this][issue 213].
* Add example for how to use ggrepel with sf objects, i.e.
`geom_text_repel(..., stat = "sf_coordinates")`, thanks to @francisbarton for [pull request 236].
* Use `expect_equal(x, y)` instead of `expect_true(identical(x, y))`, see [issue 242] for details.
[issue 213]: https://github.com/slowkow/ggrepel/issues/213
[pull request 236]: https://github.com/slowkow/ggrepel/pull/236
[issue 242]: https://github.com/slowkow/ggrepel/issues/242
ggrepel 0.9.3
========================
## Bug fixes
* When we set the seed in `ggrepel::geom_text_repel(seed = 1)`, this will
no longer override the seed for other unrelated code. Thanks to
@kassambara for reporting this in [issue 228].
[issue 228]: https://github.com/slowkow/ggrepel/issues/228
ggrepel 0.9.2
========================
## Bug fixes
* Fix compiler errors for C++ expressions like `v[i] = {0,0}` that arise
for some versions of the clang compiler. Thanks to @Krascal and @vrognas
for reporting this in [issue 184].
[issue 184]: https://github.com/slowkow/ggrepel/issues/184
* Fix warning from CRAN `warning: use of bitwise '&' with boolean operands`
## Changes
* Change internal column names, so that `ggrepel::position_nudge_repel()` can now be used
with `ggplot2::geom_text()`. This should also allow us to use new nudge functions
from the [ggpp] package by @aphalo. Thanks to @aphalo for [pull request 193].
* Improve handling of justification for `angle` different from zero in
`ggrepel::geom_text_repel()` [pull request 196].
[ggpp]: https://github.com/aphalo/ggpp
[pull request 193]: https://github.com/slowkow/ggrepel/pull/193
[pull request 196]: https://github.com/slowkow/ggrepel/pull/196
ggrepel 0.9.1 2021-01-09
========================
## Bug fixes
* Fix label positions (only for `geom_label_repel()`). The same plot would look
OK with ggrepel 0.8.2, but incorrect with ggrepel 0.9.0. Thanks to
Ben Baumer (@beanumber) for reporting this in [issue 182].
[issue 182]: https://github.com/slowkow/ggrepel/issues/182
* Fix a bug that caused R to crash (only on Windows, not on Linux or macOS) for
some specific code examples. Thanks to Pedro Aphalo (@aphalo) for reporting
this in [issue 179] and for testing the patched code.
[issue 179]: https://github.com/slowkow/ggrepel/issues/179
ggrepel 0.9.0 2020-12-14
========================
## Changes
* Points can be different sizes. Repel text labels from large points and small
points. New examples in the vignette show how to do this. See discussion about
this feature in [issue 83].
[issue 83]: https://github.com/slowkow/ggrepel/issues/83
* New parameter `max.overlaps` stops ggrepel from trying to label overcrowded
data points. The default setting is `max.overlaps = 10`, so text labels that
overlap more than 10 things (points or labels) will be excluded from further
calculations and rendering. Of course, we can set `max.overlaps = Inf` to
restore the behavior in ggrepel 0.8.1. See [issue 48] for more discussion.
We can also use `option(ggrepel.max.overlaps = Inf)` to disable this new
functionality and display all labels, regardless of too many overlaps.
[pull request 48]: https://github.com/slowkow/ggrepel/pull/48
* Add examples to the [vignette] for `ggplot2::position_jitter()` and
`ggbeeswarm::position_quasirandom()`
* Line segments can now be curved (#131, @malcolmbarrett). Add examples
to the [vignette] showing different options.
* Add support for new aesthetics:
- segment.size
- segment.colour
- segment.alpha
- segment.curvature
- segment.angle
- segment.ncp
* Add `max.time` option to limit the number of seconds spent trying to position
the text labels.
* Add `verbose` option to show timing information: seconds elapse, iteration count,
number of remaining overlaps (thanks to @MichaelChirico #159).
* Add `bg.color` and `bg.r` aesthetics for `geom_text()` to display shadows
behind text labels. Thanks to @rcannood for adding this feature with
[pull request 142].
[pull request 142]: https://github.com/slowkow/ggrepel/pull/142
## Bug fixes and improvements
* Line segments are the same color as the text by default (#164, @lishinkou).
* Text justification for multi-line text labels should be working as expected.
Thanks to @johnhenrypezzuto and @phalteman for comments in [issue 137].
[issue 137]: https://github.com/slowkow/ggrepel/issues/137
* Put text labels on top of all line segments (@kiendang). This fixes
[issue 35], where line segments sometimes appear on top of text.
[issue 35]: https://github.com/slowkow/ggrepel/issues/35
* Thanks to Paul Murrell (@pmur002) for notifying us to use `is.unit(x)`
instead of `class(x) == "unit"` in [issue 141]. This should future-proof
ggrepel for new versions of the grid package.
[issue 141]: https://github.com/slowkow/ggrepel/issues/141
* Fix the way `xlim = c(-Inf, Inf)` is treated. Thanks to @thomasp85 for
pointing out the bug in [issue 136].
[issue 136]: https://github.com/slowkow/ggrepel/issues/136
* Add new segment options. Thanks to @krassowski for adding this feature with
[pull request 151].
- segment.shape
- segment.square
- segment.squareShape
- segment.inflect
[pull request 151]: https://github.com/slowkow/ggrepel/pull/151
ggrepel 0.8.1 2019-05-07
========================
## Bug fixes and improvements
* Fix heap buffer overflow that causes R to crash. See [issue 115]. Thanks to
Brodie Gaslam (@brodieG) for helping me to setup an environment to reproduce
the bug on my own system.
[issue 115]: https://github.com/slowkow/ggrepel/issues/115
ggrepel 0.8.0 2018-05-09
========================
## Bug fixes and improvements
* Fix `geom_label_repel(..., point.padding=NA)`. Reported by @mlell in
[issue 104].
[issue 104]: https://github.com/slowkow/ggrepel/issues/104
ggrepel 0.7.3 2018-02-09
========================
## Changes
* Add support for `position` parameter. See [issue 69]. This allows us to
add text labels to points positioned with `position_jitter()`,
`position_dodge()`, `position_jitterdodge()`, etc.
Please note that this feature will not work with ggplot2 2.2.1 or older.
[issue 69]: https://github.com/slowkow/ggrepel/issues/69
ggrepel 0.7.2 2018-01-14
========================
## Bug fixes and improvements
Thanks to @AliciaSchep and @aphalo
* Fix warning about `hjust`. See [issue 93].
* Fix bug when subset of points is labeled in `geom_label_repel`.
See [issue 92].
[issue 92]: https://github.com/slowkow/ggrepel/issues/92
[issue 93]: https://github.com/slowkow/ggrepel/issues/93
ggrepel 0.7.1 2017-11-18
========================
## Changes
Thanks to @AliciaSchep
* Add support for `hjust` and `vjust` parameters. See [issue 69].
Also see new examples in the [vignette].
* Add code to avoid intersecting line segments. See [issue 34].
[issue 69]: https://github.com/slowkow/ggrepel/issues/69
[issue 34]: https://github.com/slowkow/ggrepel/issues/34
ggrepel 0.7.0 2017-09-28
========================
## Bug fixes
* Fix intersection between lines and rectangles, to reproduce the same
aesthetically pleasant behavior as in version 0.6.5.
This is an improvement on the sloppy implementation introduced in 0.6.8. See
[commit 28633d] for more information.
[commit 28633d]: https://github.com/slowkow/ggrepel/commit/28633db5eb3d3cc2bd935bd438a8bb36b5673951
ggrepel 0.6.12 2017-07-16
========================
## Changes
* Reproduce identical plots by using `seed = 1` to set the seed in
`geom_text_repel()` or `geom_label_repel()`. By default, no seed will be set.
This is an improvement on the sloppy implementation introduced in 0.6.2. See
[issue 33] and [issue 73] for more discussion of this feature. Thanks to
Pierre Gramme for reminding me about this via email.
[issue 33]: https://github.com/slowkow/ggrepel/issues/33
[issue 73]: https://github.com/slowkow/ggrepel/issues/73
ggrepel 0.6.11 2017-07-08
========================
## Changes
Thanks to @seaaan
* Allow certain parameters to be passed as numbers or `unit()`
instead of only units. See [issue 79].
[issue 79]: https://github.com/slowkow/ggrepel/issues/79
ggrepel 0.6.10 2017-03-07
========================
## Bug fixes
Thanks to @zkamvar
* Fix the crash for plots that do not specify `xlim` or `ylim`.
See [pull 74].
[pull 74]: https://github.com/slowkow/ggrepel/pull/74
ggrepel 0.6.9 2017-03-07
========================
## Bug fixes
* Fix the crash for plots with `facet_wrap` or `facet_grid` that have no
labeled points. Thanks to @pcroteau for [pull 70].
[pull 70]: https://github.com/slowkow/ggrepel/pull/70
ggrepel 0.6.8 2017-02-12
========================
## Changes
* Constrain repulsion force to x-axis "x" or y-axis "y" with `direction` in
`geom_text_repel()` and `geom_label_repel()`. Thanks to @AliciaSchep for [pull 68].
[pull 68]: https://github.com/slowkow/ggrepel/pull/68
ggrepel 0.6.7 2017-01-09
========================
## Changes
* Constrain text labels to specific areas of the plot with `xlim` and `ylim` in
`geom_text_repel()` and `geom_label_repel()`. Thanks to @lukauskas for [pull 67].
[pull 67]: https://github.com/slowkow/ggrepel/pull/67
ggrepel 0.6.6 2016-11-28
========================
## Bug fixes
* Mathematical expressions as labels with `parse = TRUE` in
`geom_text_repel()` and `geom_label_repel()`.
Thanks to @fawda123 for [issue 60].
[issue 60]: https://github.com/slowkow/ggrepel/issues/60
ggrepel 0.6.5 2016-11-22
========================
## Changes
Thanks to @jiho for these:
* changed `alpha` in `geom_label_repel()` to control text, label
background, label border, and segment.
* Allow `segment.colour` as well as `segment.color`.
* By default, map text color and text alpha to the segment color unless they
are overridden.
* Call `scales::alpha()` instead of `alpha()`.
ggrepel 0.6.4 2016-11-08
========================
## Bug fixes
* Fix a bug that caused ggrepel to fail on polar coordinates `coord_polar()`.
See [issue 56].
[issue 56]: https://github.com/slowkow/ggrepel/issues/56
ggrepel 0.6.3 2016-10-14
========================
## Changes
* Use `point.padding=NA` to ignore data points in repulsion calculations.
ggrepel 0.6.2 2016-10-06
========================
## Bug fixes
* Stop the labels from escaping the plot boundaries instead of applying
a force at the boundary.
* Call `set.seed` within `geom_text_repel()` and `geom_label_repel()` to
allow recreating identical plots. Thanks to @erikor for [issue 33].
[issue 33]: https://github.com/slowkow/ggrepel/issues/33
## Changes
* Add `min.segment.length` to `geom_text_repel()` and `geom_label_repel()`.
ggrepel 0.6.1 2016-10-04
========================
## Changes
* Tweak `repel_boxes.cpp`. Dampen forces to tune how the labels move. The
result looks better, at least for the examples in the [vignette].
ggrepel 0.6.0 2016-10-03
========================
## Changes
* Do not draw labels with empty strings. When a label is an empty string,
the text will not be shown, the segment will not be drawn, but the
corresponding data point will repel other labels. See [issue 51].
[issue 51]: https://github.com/slowkow/ggrepel/issues/51
* Add `segment.alpha` as an option for `geom_text_repel()` and
`geom_label_repel()`.
* Implement `angle` aesthetic for `geom_text_repel()`, the same way as done in
ggplot2 `geom_text()`.
* Move `nudge_x` and `nudge_y` out of the aesthetics function `aes()`. This
makes ggrepel consistent with ggplot2 functions `geom_text()` and
`geom_label()`. Backwards incompatible with 0.5.1.
* Restore `segment.color` as an option for `geom_text_repel()` and
`geom_label_repel()`.
* Tweak `repel_boxes.cpp`. Do not weight repulsion force by ratios of bounding
box heights and widths. This seems to perform better, especially after
rotating text labels.
ggrepel 0.5.1 2016-02-22
========================
* Optimize C++ code further by reducing number of calls to `rnorm()`.
ggrepel 0.5 2016-02-08
========================
* First push to CRAN.
ggrepel 0.4.6 2016-02-07
========================
## Changes
* Tweak `point.padding` so that users can configure how far labels are pushed
away from data points.
ggrepel 0.4.5 2016-02-06
========================
## Changes
* Optimize C++ code for a 2.5X speed improvment.
* Delete unnecessary .Rd files.
ggrepel 0.4.4 2016-02-05
========================
FIXES
* Fix the bug when the line segment from the data point points to the origin
at (0,0) instead of the text label.
## Changes
* Automatically recompute repulsion between labels after resizing the plot.
ggrepel 0.4.3 2016-01-18
========================
## Changes
* Change distance between segment and label in `geom_label_repel()`. Now there
is no gap between the end of the segment and the label border.
ggrepel 0.4.2 2016-01-15
========================
FIXES
* Fix `spring_force()` so that it never returns NaN.
## Changes
* Add `nudge_x` and `nudge_y` to better control positioning of labels.
ggrepel 0.4.1 2016-01-13
========================
## Changes
* Add `arrow` parameter to allow plotting arrows that point to the labeled data
points rather than plain line segments.
* Always draw segments, even if the labeled point is very close to the label.
FIXES
* Fix `point.padding` so that horizontal and vertical padding is calculated
correctly.
* Tweak forces to improve layout near borders and in crowded areas.
ggrepel 0.4 2016-01-12
========================
## Bug fixes
* Fix [issue 7]. Labels can now be placed anywhere in the plotting area
instead of being limited to the x and y ranges of their corresponding data
points.
[issue 7]: https://github.com/slowkow/ggrepel/issues/7
* Fix DESCRIPTION to require ggplot2 >= 2.0.0
## Changes
* Add new parameter `point.padding` to add padding around the labeled points.
The line segment will stop before reaching the coordinates of the point. The
text labels are also now padded from the line segment to improve legibility.
* Add volcano plot to the [vignette] usage examples.
* Add Travis continuous integration to test against R-devel, R-release, and
R-oldrel.
* Dampen repulsion force to slightly improve algorithm efficiency.
* Move `intersect_line_rectangle()` to `src/repel_boxes.cpp`.
ggrepel 0.3 2016-01-08
========================
## Changes
* Remove unused imports: `colorspace`.
* Update NAMESPACE with new version of roxygen.
* Use spring force to attract each label to its own point.
* Change default maximum iterations from 10,000 to 2000.
* Update man pages.
* Remove unused code.
ggrepel 0.2.0 2016-01-07
========================
## Changes
* Update `geom_text_repel()` and `geom_label_repel()`.
* Change `label.padding` to `box.padding`.
* Remove unsupported parameters:
* position
* nudge_x
* nudge_y
* hjust
* vjust
* Remove unused imports.
## Documentation
* Add roxygen docs to all functions.
ggrepel 0.1.0 2016-01-05
========================
## Changes
* Add `geom_label_repel()`.
* Add fudge width to help with legends.
* Add `expand=TRUE` to allow text to be placed in the expanded plot area.
* Add man/ folder.
* Add links to ggplot2 docs in [vignette].
* Add unused R implementation of `repel_boxes()`, just for your reference.
ggrepel 0.0.1 2016-01-04
========================
* Initial release to github.
[vignette]: https://github.com/slowkow/ggrepel/blob/master/vignettes/ggrepel.Rmd
ggrepel/inst/ 0000755 0001762 0000144 00000000000 14667131606 012666 5 ustar ligges users ggrepel/inst/doc/ 0000755 0001762 0000144 00000000000 14667131606 013433 5 ustar ligges users ggrepel/inst/doc/ggrepel.Rmd 0000644 0001762 0000144 00000006141 13765535370 015532 0 ustar ligges users ---
title: "Getting started with ggrepel"
author: "Kamil Slowikowski"
date: "`r Sys.Date()`"
output:
prettydoc::html_pretty:
theme: hpstr
highlight: github
toc: true
mathjax: null
self_contained: true
vignette: >
%\VignetteIndexEntry{ggrepel examples}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---
```{r setup, echo=FALSE, results='hide', warning=FALSE, error=FALSE, message=FALSE, cache=FALSE}
# output:
# prettydoc::html_pretty:
# theme: hpstr
# highlight: github
# toc: true
# mathjax: null
# self_contained: true
# output:
# html_document:
# css: style.css
# highlight: pygments
# mathjax: null
# self_contained: true
# toc: true
# toc_float:
# collapsed: false
# smooth_scroll: false
library(knitr)
opts_chunk$set(
cache = FALSE,
autodep = TRUE,
echo = FALSE,
warning = FALSE,
error = FALSE,
message = FALSE,
out.width = 700,
fig.width = 12,
fig.height = 8,
dpi = 300,
# cache.path = "cache/ggrepel/",
# fig.path = "figures/ggrepel/",
pngquant = "--speed=1 --quality=0-10",
concordance = TRUE
)
knit_hooks$set(
pngquant = hook_pngquant
)
library(gridExtra)
library(ggplot2)
theme_set(theme_classic(base_size = 18) %+replace% theme(
# axis.line.y = element_line(colour = "black", size = 0.2),
# axis.line.x = element_line(colour = "black", size = 0.2),
axis.ticks = element_line(colour = "black", size = 0.3),
panel.background = element_rect(size = 0.3, fill = NA),
axis.line = element_blank(),
plot.title = element_text(size = 18, vjust = 2, hjust = 0.5),
strip.text = element_text(size = 18),
strip.background = element_blank()
))
```
## Overview
ggrepel provides geoms for [ggplot2] to repel overlapping text labels:
- `geom_text_repel()`
- `geom_label_repel()`
[ggplot2]: https://ggplot2.tidyverse.org/
Text labels repel away from each other, away from data points, and away
from edges of the plotting area (panel).
Let's compare `geom_text()` and `geom_text_repel()`:
```{r comparison, echo=TRUE, fig.width=9, fig.height=4}
library(ggrepel)
set.seed(42)
dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
dat$car <- rownames(dat)
p <- ggplot(dat, aes(wt, mpg, label = car)) +
geom_point(color = "red")
p1 <- p + geom_text() + labs(title = "geom_text()")
p2 <- p + geom_text_repel() + labs(title = "geom_text_repel()")
gridExtra::grid.arrange(p1, p2, ncol = 2)
```
## Installation
ggrepel is available on [CRAN]:
```{r install-cran, echo=TRUE, eval=FALSE}
install.packages("ggrepel")
```
The [latest development version][github] may have new features, and you can get
it from GitHub:
```{r install-github, echo=TRUE, eval=FALSE}
# Use the devtools package
# install.packages("devtools")
devtools::install_github("slowkow/ggrepel")
```
[CRAN]: https://CRAN.R-project.org/package=ggrepel
[github]: https://github.com/slowkow/ggrepel
## Usage
See the [examples] page to learn more about how to use ggrepel in your project.
[examples]: https://ggrepel.slowkow.com/articles/examples.html
ggrepel/inst/doc/ggrepel.R 0000644 0001762 0000144 00000004127 14667131605 015206 0 ustar ligges users ## ----setup, echo=FALSE, results='hide', warning=FALSE, error=FALSE, message=FALSE, cache=FALSE----
# output:
# prettydoc::html_pretty:
# theme: hpstr
# highlight: github
# toc: true
# mathjax: null
# self_contained: true
# output:
# html_document:
# css: style.css
# highlight: pygments
# mathjax: null
# self_contained: true
# toc: true
# toc_float:
# collapsed: false
# smooth_scroll: false
library(knitr)
opts_chunk$set(
cache = FALSE,
autodep = TRUE,
echo = FALSE,
warning = FALSE,
error = FALSE,
message = FALSE,
out.width = 700,
fig.width = 12,
fig.height = 8,
dpi = 300,
# cache.path = "cache/ggrepel/",
# fig.path = "figures/ggrepel/",
pngquant = "--speed=1 --quality=0-10",
concordance = TRUE
)
knit_hooks$set(
pngquant = hook_pngquant
)
library(gridExtra)
library(ggplot2)
theme_set(theme_classic(base_size = 18) %+replace% theme(
# axis.line.y = element_line(colour = "black", size = 0.2),
# axis.line.x = element_line(colour = "black", size = 0.2),
axis.ticks = element_line(colour = "black", size = 0.3),
panel.background = element_rect(size = 0.3, fill = NA),
axis.line = element_blank(),
plot.title = element_text(size = 18, vjust = 2, hjust = 0.5),
strip.text = element_text(size = 18),
strip.background = element_blank()
))
## ----comparison, echo=TRUE, fig.width=9, fig.height=4-------------------------
library(ggrepel)
set.seed(42)
dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
dat$car <- rownames(dat)
p <- ggplot(dat, aes(wt, mpg, label = car)) +
geom_point(color = "red")
p1 <- p + geom_text() + labs(title = "geom_text()")
p2 <- p + geom_text_repel() + labs(title = "geom_text_repel()")
gridExtra::grid.arrange(p1, p2, ncol = 2)
## ----install-cran, echo=TRUE, eval=FALSE--------------------------------------
# install.packages("ggrepel")
## ----install-github, echo=TRUE, eval=FALSE------------------------------------
# # Use the devtools package
# # install.packages("devtools")
# devtools::install_github("slowkow/ggrepel")
ggrepel/inst/doc/ggrepel.html 0000644 0001762 0000144 00000363621 14667131606 015761 0 ustar ligges users
Getting started with ggrepel
# Use the devtools package# install.packages("devtools")devtools::install_github("slowkow/ggrepel")
Usage
See the examples
page to learn more about how to use ggrepel in your project.
ggrepel/README.md 0000644 0001762 0000144 00000020370 14547311112 013157 0 ustar ligges users ggrepel
============================================
[![Build Status][bb]][githubactions] [![CRAN_Status_Badge][cb]][cran] [![CRAN_Downloads_Badge][db]][r-pkg]
[bb]: https://github.com/slowkow/ggrepel/workflows/R-CMD-check/badge.svg
[githubactions]: https://github.com/slowkow/ggrepel/actions?query=workflow%3AR-CMD-check
[cb]: https://www.r-pkg.org/badges/version/ggrepel?color=blue
[cran]: https://CRAN.R-project.org/package=ggrepel
[db]: https://cranlogs.r-pkg.org/badges/ggrepel
[r-pkg]: https://cranlogs.r-pkg.org
Overview
--------
ggrepel provides geoms for [ggplot2] to repel overlapping text labels:
[ggplot2]: https://ggplot2.tidyverse.org
- `geom_text_repel()`
- `geom_label_repel()`
Text labels repel away from each other, away from data points, and away
from edges of the plotting area.
```r
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_text_repel() +
geom_point(color = 'red') +
theme_classic(base_size = 16)
```
Installation
------------
```r
# The easiest way to get ggrepel is to install it from CRAN:
install.packages("ggrepel")
# Or get the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("slowkow/ggrepel")
```
Usage
-----
See the [examples] page to learn more about how to use ggrepel in your project.
[examples]: https://ggrepel.slowkow.com/articles/examples.html
Examples
--------
Click one of the images below to go to see the code example:
Contributing
------------
Please [submit an issue][issues] to report bugs or ask questions.
Please contribute bug fixes or new features with a [pull request][pull] to this
repository.
[issues]: https://github.com/slowkow/ggrepel/issues
[pull]: https://help.github.com/articles/using-pull-requests/
ggrepel/build/ 0000755 0001762 0000144 00000000000 14667131606 013010 5 ustar ligges users ggrepel/build/vignette.rds 0000644 0001762 0000144 00000000312 14667131606 015343 0 ustar ligges users b```b`abf "fa @ ӋRRsrSФR
9h<0%9hrpcNK@ Bּ\]zR@g;<E
T
[fN*ސ89
dBw(,/׃
@?{49'ݣ\)%ziE@ w P ggrepel/man/ 0000755 0001762 0000144 00000000000 14532674424 012465 5 ustar ligges users ggrepel/man/ggrepel.Rd 0000644 0001762 0000144 00000004705 14667115467 014415 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom-label-repel.R, R/geom-text-repel.R,
% R/ggrepel-package.R, R/position-nudge-repel.R
\docType{data}
\name{GeomLabelRepel}
\alias{GeomLabelRepel}
\alias{GeomTextRepel}
\alias{ggrepel}
\alias{PositionNudgeRepel}
\title{GeomLabelRepel}
\description{
This package contains extra geoms for \pkg{ggplot2}.
}
\details{
Please see the help pages listed below:
\itemize{
\item \code{\link{geom_text_repel}}
\item \code{\link{geom_label_repel}}
}
Also see the vignette for more usage examples:
\code{browseVignettes("ggrepel")}
Please report issues and suggest improvements at Github:
\url{https://github.com/slowkow/ggrepel}
}
\seealso{
\link[ggplot2]{GeomLabel} from the ggplot2 package.
\link[ggplot2]{GeomText} from the ggplot2 package.
Useful links:
\itemize{
\item \url{https://ggrepel.slowkow.com/}
\item \url{https://github.com/slowkow/ggrepel}
\item Report bugs at \url{https://github.com/slowkow/ggrepel/issues}
}
}
\author{
\strong{Maintainer}: Kamil Slowikowski \email{kslowikowski@gmail.com} (\href{https://orcid.org/0000-0002-2843-6370}{ORCID})
Other contributors:
\itemize{
\item Alicia Schep (\href{https://orcid.org/0000-0002-3915-0618}{ORCID}) [contributor]
\item Sean Hughes (\href{https://orcid.org/0000-0002-9409-9405}{ORCID}) [contributor]
\item Trung Kien Dang (\href{https://orcid.org/0000-0001-7562-6495}{ORCID}) [contributor]
\item Saulius Lukauskas [contributor]
\item Jean-Olivier Irisson (\href{https://orcid.org/0000-0003-4920-3880}{ORCID}) [contributor]
\item Zhian N Kamvar (\href{https://orcid.org/0000-0003-1458-7108}{ORCID}) [contributor]
\item Thompson Ryan (\href{https://orcid.org/0000-0002-0450-8181}{ORCID}) [contributor]
\item Dervieux Christophe (\href{https://orcid.org/0000-0003-4474-2498}{ORCID}) [contributor]
\item Yutani Hiroaki [contributor]
\item Pierre Gramme [contributor]
\item Amir Masoud Abdol [contributor]
\item Malcolm Barrett (\href{https://orcid.org/0000-0003-0299-5825}{ORCID}) [contributor]
\item Robrecht Cannoodt (\href{https://orcid.org/0000-0003-3641-729X}{ORCID}) [contributor]
\item Michał Krassowski (\href{https://orcid.org/0000-0002-9638-7785}{ORCID}) [contributor]
\item Michael Chirico (\href{https://orcid.org/0000-0003-0787-087X}{ORCID}) [contributor]
\item Pedro Aphalo (\href{https://orcid.org/0000-0003-3385-972X}{ORCID}) [contributor]
\item Francis Barton [contributor]
}
}
\keyword{internal}
ggrepel/man/figures/ 0000755 0001762 0000144 00000000000 14424224753 014125 5 ustar ligges users ggrepel/man/figures/logo.svg 0000644 0001762 0000144 00000007635 13412707236 015617 0 ustar ligges users