-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking bugs and features #8
Comments
The latest commit should fix the curvature / spacing problem. It turns out that the spiral is a really useful test - you should notice that this looks nicer at all aspect ratios now if you look at the updated readme. I have ticked this off the above list, though I wonder if once we are done with the above problems we should just make a separate issue for each. |
We should now have line breaks implemented: library(geomtextpath)
#> Loading required package: ggplot2
spiral <- data.frame(x = rev(sin(seq(0, 5*pi, length.out = 1000)) * 1000:1),
y = rev(cos(seq(0, 5*pi, length.out = 1000)) * 1000:1),
s = seq(1, 10, length.out = 1000),
z = paste("Like a circle in a spiral, like a",
"wheel within a wheel, never ending",
"or beginning on an ever spinning reel"))
spiral$z <- paste(spiral$z, spiral$z, sep = "\n")
ggplot(spiral, aes(x, y, label = z)) +
geom_textpath(size = 5, linewidth = 0, vjust = 2) +
coord_equal(xlim = c(-1500, 1500), ylim = c(-1500, 1500)) library(geomtextpath)
#> Loading required package: ggplot2
ggplot(within(iris, Species <- paste("This is", Species, sep = "\n")),
aes(x = Sepal.Length, color = Species)) +
geom_textpath(aes(label = Species),
size = 5, stat = "density",
fontface = 2, hjust = 0.1, vjust = 0.9) I've had to split the lines into different groups, each with their own |
Tracking is now exposed to end users as a "spacing" parameter in geom_textpath: library(geomtextpath)
#> Loading required package: ggplot2
ggplot(iris, aes(x = Sepal.Length, color = Species)) +
geom_textpath(aes(label = Species),
size = 6, stat = "density",
fontface = 2, hjust = 0.2)
ggplot(iris, aes(x = Sepal.Length, color = Species)) +
geom_textpath(aes(label = Species),
size = 6, stat = "density",
fontface = 2, hjust = 0.2, spacing = 100) ggplot(iris, aes(x = Sepal.Length, color = Species)) +
geom_textpath(aes(label = Species),
size = 6, stat = "density",
fontface = 2, hjust = 0.2, spacing = 1000)
ggplot(iris, aes(x = Sepal.Length, color = Species)) +
geom_textpath(aes(label = Species),
size = 6, stat = "density",
fontface = 2, hjust = 0.2, spacing = -100) Created on 2021-11-18 by the reprex package (v2.0.0) |
Through a stroke of luck in #9, flipping labels are fixed: library(geomtextpath)
#> Loading required package: ggplot2
df <- data.frame(x = 1:1000, y = 1, text = "This is a perfectly flat label")
ggplot(df, aes(x, y, label = text)) +
geom_textpath(size = 6) +
coord_polar(start = pi) Created on 2021-11-18 by the reprex package (v1.0.0) |
Sorry about all the automation fails Teun. I now have it so that the readme updates automatically - it's actually quite useful as a visual test following a commit, and I was finding it tiresome to manually knit the rmd every time I committed. |
Nice work with all the tracking, line breaks and automation Allan! Everything seems to be coming along very smoothly! |
This comment has been minimized.
This comment has been minimized.
It would be nice if we can have a Notice that in the example below, the textbox placement relative to the reference points (red) is controlled by the library(ggtext)
library(ggplot2)
df <- expand.grid(
x = c(0, 0.5, 1),
y = c(0, 0.5, 1),
text = "This is a<br>multi-line<br>string for<br>demonstration."
)
ggplot(df, aes(x = x, y = y, label = text)) +
geom_textbox(
aes(hjust = x,
halign = y),
width = unit(1.5, "inch")
) +
geom_point(colour = "red") +
labs(x = "hjust", y = "halign") +
scale_y_continuous(expand = c(0.2,0)) Created on 2021-11-22 by the reprex package (v2.0.1) |
Yes, I'd had the same thought. The multi-line text support seems disproportionately complex to get right. I'm currently working on a method for allowing flipping of upside-down text, which might make it even harder... |
I think the multi-line support could be relatively straightforward by taking the |
It could maybe be easier this way, but it's not the calculation of the correct y position that's the difficult part (I think I have this correctly calculated from the number of lines of text, the vjust and the lineheight). The difficult part is that the curvature is different for different lines of text. To preserve the correct letter spacing in different lines we need to work out the curvature for each line of text and correct for it. Imagine the text is on the inside of a circle. If you decrease the vjust from 0 to -1, the text moves towards the centre of the circle, and the string squashes in, so you need to account for that by calculating an "adjusted length" - this is the length of the offset path at vjust = -1. That's what we currently do with the curvature calculation. For multi-line text, the natural way to do this is by breaking up the text line by line and calculating the path for each line separately, which is what happens currently. You may find a creative way round this, but my instinct is that it's inherently complicated. I certainly had a few false starts trying to get it right in the first place. |
The bugs in this issue are fixed, and the feature requests are now implemented. |
It's good that we have identified some issues and ideas that we want to keep track of, but these are currently mentioned all over the place. I thought it could be useful to have a checklist issue to keep track of bugs we're aware of. Plus, it is very satisfying to check off things from a checklist. Feel free to comment additional ones as you encounter them.
Bugs
.get_surrounding_lines()
.Features
geom_textpath()
(Ageom
similar togeom_text
but curves in polar co-ordinates #5).shape_string(tracking = ...)
argument to user to finetune letter spacing (Line breaks don't work #4 (comment)).halign
parameter for alignment of multi-line strings (see example in comments)The text was updated successfully, but these errors were encountered: