Comments (3)
Yes overplotting is an issue with any geom you make and I don't think it is our power to counter every possible case of overlaps. Of course, the core business of {ggrepel} is to avoid overlapping text and while we might give some options to avoid it, the core of the package is to place text along paths.
There is an additional example I could think of that counters overplotting, and that is to use the labels to hide the overlapping bits.
library(geomtextpath)
#> Loading required package: ggplot2
df <- data.frame(x = rep(0:1, each = 3),
y = c(0, 2, 2.1),
z = paste("Example", 1:3))
p <- ggplot(df, aes(x, y, label = z, group = z)) + ylim(c(0, 2.5))
p <- p + geom_labelline(
size = 8, boxcolour = NA,
fill = theme_get()$panel.background$fill,
label.padding = unit(0, "pt")
)
p
Created on 2022-01-02 by the reprex package (v2.0.1)
such as collision detection etc
Collision detection would be nice, but I indeed think it would be overkill. We could use polyclip::pointinpolygon()
in combination with our curved textboxes to check if they overlap, but the problem here is that you have to cross-check every textbox with every other textbox, which can be quite expensive to do every time the window is resized. All in all I think collision detection could go in the low importance low urgency part of the Eisenhower matrix.
I have added a scales.R file that allows a full range of hjust and vjust scale functions.
I think the scales are a good idea but there are a two things I'm concerned about.
- We're inadvertently changing the behaviour of vanilla ggplot2. In the example below, once we load {geomtextpath} the output of the plot is changed. Notice how in the first bit the ABC and GHI labels do not touch the x = 1 and x = 3 points. Whereas after we load our package, the
hjust
is rescaled to the [0,1] interval and the labels do touch those points. I think the easiest solution to this problem, is to simply delete thescale_{h/v}just_continuous()
variant.
library(ggplot2)
df <- data.frame(
x = 1:3,
xend = 1:3 + 0.5,
y = 0,
yend = 0,
label = c("ABC", "DEF", "GHI")
)
p <- ggplot(df, aes(x, y, label = label)) +
geom_text(aes(hjust = c(-1, 0.5, 2)))
p
library(geomtextpath)
p
Created on 2022-01-02 by the reprex package (v2.0.1)
- I think the default guide for these scales should be the
"none"
guide. You can see in the example above that the guide adds absolutely nothing to the understanding of the plot.
from geomtextpath.
I have made the changes discussed above.
In addition, I have added the ability to remove text from paths that are not long enough to support them. Unfortunately this means another parameter and has to be done inside makeContent
. However, the calculation isn't expensive, and only occurs when the new parameter, remove_long
is set set to TRUE
.
The main reason for doing this was horrendous overplotting in geom_textsf
. Without this technique, the plot looked like this:
df <- data.frame(x = c(-4.2518, -3.1883),
y = c(55.8642, 55.9533),
label = c("Glasgow", "Edinburgh"))
ggplot(data = df) +
geom_textsf(data = waterways,
aes(label = name), text_smoothing = 99.5, linecolour = "#8888B3",
color = "gray30", hjust = 0.25, vjust = -0.5, fill = "#E6F0B3",
alpha = 0.8, fontface = 3, size = 3) +
geom_point(aes(x, y), data = df, color = "gray50", size = 3) +
geom_textpath(aes(x, y, label = label), color = "gray50",
hjust = c(-0.2, 1.2)) +
theme(panel.grid = element_line()) +
lims(x = c(-4.7, -3), y = c(55.62, 56.25))
But with the new technique the same plot looks like this:
from geomtextpath.
Thanks Teun
I completely agree with your sentiments here. I don't think we can or should work too hard on the problem of overplotting, other than providing some options to allow users the ability to easily shift the labels around. The example that you give of using labels for masking works quite well, but would apply equally well to plain old geom_text
, and the ggplot authors haven't bothered to implement any automation of this, so I don't think we need to either.
I think the easiest solution to this problem, is to simply delete the scale_{h/v}just_continuous() variant
I hadn't noticed this effect on vanilla ggplot, and I think you're right - I will delete the continuous variants.
I think the default guide for these scales should be the "none" guide.
I thought the guides were already defaulted to "none", but clearly they aren't. I will make the necessary changes.
from geomtextpath.
Related Issues (20)
- Option for line width and/or font size control when using 'size = ___' for geom_textsmooth() HOT 2
- geom_textsegment() with arrow() draws line to the top left of the plot HOT 4
- Denisty fill HOT 6
- label border? HOT 2
- geom_textsmooth() doesn't choose method if not explicitly set HOT 2
- Request something like "dodge" along path HOT 3
- Chinese character support HOT 3
- geom_labelsf() not recognizing aesthetics HOT 5
- While working with ragg, minuses aren't drawn HOT 2
- geom_textpath() always draw a empty box when label is ""
- Ignoring unknown parameters: text_smoothing HOT 10
- Feature request - multiple labels per line HOT 7
- geom_textsmooth computation fails if method argument is not specified HOT 3
- ggplot2 is separating size and linewidth HOT 2
- Negative values in geom_textcontour not appearing HOT 1
- geom_textlinerange HOT 1
- Question on angle
- text_only in geom_labelsegment
- Feature request - avoid text overlapping
- two labels on same curve HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geomtextpath.