You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the repel works to repel text away from single points. However, it would be great if it could repel text away from segments as well. This would be especially useful for automatically generating nice biplots for multivariate analysis (PCA, RDA, etc.).
Minimal code example
Here is the minimum amount of code needed to demonstrate the issue:
library(ggplot2)
library(ggrepel)
## 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))
## We plot the two primary principal componenets and add species labels
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"))) +
geom_text_repel() +
xlim(-5, 5) +
ylim(-2, 2) +# Stadard settings for displaying biplots
geom_hline(aes(yintercept=0), size=.2) +
geom_vline(aes(xintercept=0), size=.2) +
coord_fixed()
Here is an image of the output produced by the code:
Suggestions
The text should be repelled in the direction of the arrow with which it is associated. If the geom_text_repel() function could take as input the aesthetics xend and yend. If these aesthetics are supplied, the text is placed at coordinates yend and xend and some invisible points along the segment are added to the plot in order to repel the text away from the line. An additional option force_line would also be useful to determine the force with which the lines repel the text.
Version information
Here is the output from sessionInfo() in my R session:
At least for this simple example adding radial nudging away from the origin gives the desired result. NOTE: This is using ggrepel under development and ggpp (>= 0.4.2) from CRAN.
library(ggplot2)
library(ggrepel)
library(ggpp)
#> #> Attaching package: 'ggpp'#> The following object is masked from 'package:ggplot2':#> #> annotate## 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))
## We plot the two primary principal componenets and add species labels
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"))) +
geom_text_repel(position= position_nudge_center(0.2, 0.1, 0, 0)) +
xlim(-5, 5) +
ylim(-2, 2) +# Stadard settings for displaying biplots
geom_hline(aes(yintercept=0), size=.2) +
geom_vline(aes(xintercept=0), size=.2) +
coord_fixed()
Summary
Thanks for the great package!
Currently, the repel works to repel text away from single points. However, it would be great if it could repel text away from segments as well. This would be especially useful for automatically generating nice biplots for multivariate analysis (PCA, RDA, etc.).
Minimal code example
Here is the minimum amount of code needed to demonstrate the issue:
Here is an image of the output produced by the code:
Suggestions
The text should be repelled in the direction of the arrow with which it is associated. If the
geom_text_repel()
function could take as input the aestheticsxend
andyend
. If these aesthetics are supplied, the text is placed at coordinatesyend
andxend
and some invisible points along the segment are added to the plot in order to repel the text away from the line. An additional optionforce_line
would also be useful to determine the force with which the lines repel the text.Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: