Comments (8)
Oh, I see what you mean. I can't think of any reason why it couldn't be done beforehand, which would obviously be preferable from the performance point of view.
from geomtextpath.
Nice work Alan! These look good to me: the bezier solution seems nice for underdefined paths and the spline solution seems nice for overdefined paths.
But I know from the blogpost I recently mentioned that people dislike it if their text intersects the path. It might therefore be nice if, for example, the radius of the bezier curve doesn't exceed the first true offset distance. I think we also mentioned some convex/concave hull-type of thing to specifically mitigate text/path intersections, but I hadn't the time to explore the options in this sense.
from geomtextpath.
Sorry I just recalled something. If this is primarily for the sf
variant due to it having no access to smoothing stats, is this something we could do before makeContent
?
from geomtextpath.
I really think we need a general smoother for text. The blog post you linked was a good example - I think that most paths from real-world examples will need text smoothing. Line plots are generally either geometric or noisy, with only a relatively small subset being smooth.
I'm pretty sure if I was an end-user coming across this package, I would expect it to be easy to smooth the text label on an arbitrary path without running gam
or similar - at most setting some smoothing parameter.
from geomtextpath.
Yes, I agree with you. My point wasn't about whether we need it, it seems very useful, my question was about whether we'd need to repeat the smoothing every time the window is resized.
from geomtextpath.
The latest commit includes a version of text smoothing that works fairly well. It requires a copy of the smoothed x, y co-ordinates to be passed along with the original path into the makeContent functions. The smoothing algorithms try to keep track of the mapping between the original and the smoothed path to get the line gaps right. At the moment, this works fairly well, but the "noisy smoother" isn't quite perfect in its ability to map when the smoothing is high, However, the mechanism is now in place and the algorithm is located in a single small function that can be tweaked as needed.
Current behaviour is as follows:
library(geomtextpath)
#> Loading required package: ggplot2
df <- data.frame(x = 1:5, y = c(1, 3, 3, 1, 5))
p <- ggplot(df, aes(x, y, label = "A reasonably long text label"))
p + geom_textpath(size = 5, hjust = 0.24)
p + geom_textpath(size = 5, hjust = 0.24, text_smoothing = 90)
p + geom_textpath(size = 5, hjust = 0.24, vjust = -1.5)
p + geom_textpath(size = 5, hjust = 0.24, vjust = -1.5, text_smoothing = 90)
p + geom_labelpath(size = 5, hjust = 0.24, vjust = -1.5)
p + geom_labelpath(size = 5, hjust = 0.24, vjust = -1.5, text_smoothing = 90)
The noisy path smoother also works fairly well, and I have moved the economics example to a brief new section in the readme to demonstrate.
I have also put it to practical use to improve the look of the geom_textsf
and richtext examples.
I will keep this issue open until I am happier with the algorithm, and you've had a chance to review the changes @teunbrand
Created on 2021-12-31 by the reprex package (v2.0.1)
from geomtextpath.
This looks pretty good already! Nice work Alan!
At the moment, this works fairly well, but the "noisy smoother" isn't quite perfect
Without smoothing, the point where the path is cut isn't very intuitive either (notice the 'e' intersecting the path for example).
library(geomtextpath)
#> Loading required package: ggplot2
ggplot(economics, aes(date, unemploy)) +
geom_textpath(label = "Decline", vjust = 1)
With some smoothing, it already looks much better.
ggplot(economics, aes(date, unemploy)) +
geom_textpath(label = "Decline", vjust = 1, text_smoothing = 50)
Created on 2022-01-02 by the reprex package (v2.0.1)
I'm wondering whether padding = unit(0.15, "inch")
isn't setting too wide a margin. Do you think we should set the default somewhat smaller? I think using unit(5, "pt")
or unit(0.05, "inch")
tends to look better in most cases.
from geomtextpath.
Do you think we should set the default somewhat smaller?
I'm happy to have a smaller gap - it does look a bit large to me, especially at default text sizes
from geomtextpath.
Related Issues (20)
- Long labels with arrow throw cryptic "Error: Cannot create zero-length unit vector ("unit" subsetting)" error
- Strange behaviour of halign HOT 4
- Feature Request: Set angle for geom_labelvline HOT 6
- Feature request - test for text self-overlap on sharp contours HOT 1
- ggplot coord_polar() issue with multiple classes: 'from' must be a finite number error HOT 1
- session aborted when library in Rstudio HOT 2
- text_only in geom_labelsegment
- Feature request - avoid text overlapping
- two labels on same curve HOT 5
- straight argument unknown in geom_textsf() HOT 2
- `label` aesthetic in `geom_textdensity2d` HOT 2
- R 4.3.0 and glyphs 👀 HOT 1
- Can't get things to work HOT 11
- vjust and hjust as aesthetics in geom_textsf HOT 3
- Different behavior for line breaks when there's no data
- geomtextline not accommodating RGBA colors
- show.legend not working in geom_textabline
- Support for `geom_step()`? HOT 2
- Partial match of 'xoff' to 'xoffset'
- geom_textsf seems to ignore remove_long=F
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.