See the package examples for more use cases.
Example of geom_label_repel. That is the first line of the lege. Alignment with hjust or vjust. Hide some of the labels.
If requireNamespacegghighlight quietly TRUE librarygghighlight ggplotnc geom_sfaesfill AREA gghighlightAREA 020 geom_sf_label_repel aeslabel NAME force 100 nudge_x -2. We use the ggrepel function geom_label_repel to add labels and automatically make sure text will not overlap. Setseed 42 ggplot mtcars geom_point aes wt mpg size 5 color grey geom_label_repel aes wt mpg fill factor cyl label rownames mtcars fontface bold color white boxpadding unit 035 lines pointpadding unit 05 lines segmentcolor grey50 theme_classic base_size 16.
In this post we will see how to add labels or annotations to select data points such that the labels dont overlap with each other. To add labels at specified points use annotate with annotategeom text or annotategeom label. The most common auxiliary aesthetic properties that we use for geom_label are properties for text alignment horizontal and vertical alignment.
Show the value of a geom_point using geom_text Using this nice code from here. Minimal code example. This is again because geom_label_repel looks for the aes layer globally in the ggplot function.
You notice that we have a weird a in the legend and also the text is colored. Geom_label_repel mapping NULL data NULL stat identity position identity parse FALSE boxpadding 025 labelpadding 025 pointpadding 1e-06 labelr 015 labelsize 025 minsegmentlength 05 arrow NULL force 1 force_pull 1 maxtime 05 maxiter 10000 maxoverlaps getOptionggrepelmaxoverlaps default 10 nudge_x 0 nudge_y 0 xlim cNA NA. X argument must be a unit object.
Align labels on the top or bottom edge. Geom_label_repel mapping NULL data NULL stat identity position identity parse FALSE boxpadding 025 labelpadding 025 pointpadding 1e-06 labelr 015 labelsize 025 minsegmentlength 05 arrow NULL force 1 force_pull 1 maxtime 05 maxiter 10000 maxoverlaps getOption ggrepelmaxoverlaps default 10 nudge_x 0 nudge_y 0 xlim c NA NA. The example is shown in the following plot.