-
Notifications
You must be signed in to change notification settings - Fork 24
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
Plotmath and expressions #25
Comments
I have started implementing this. My approach was to keep the labels flat but angled rather than trying to curve them. Expressions need to be handled differently from text, but I thought the best thing to do was to try to create the same output structure that When we implement the "dumb" textpath, we should probably make every expression "dumb", though the placement is good on smooth curves at present. Current behaviour is: library(geomtextpath)
#> Loading required package: ggplot2
lab <- expression(paste("y = ", frac(1, sigma*sqrt(2*pi)), " ",
plain(e)^{frac(-(x-mu)^2, 2*sigma^2)}))
df <- data.frame(x = seq(-2, 0, len = 100),
y = dnorm(seq(-2, 0, len = 100)),
z = as.character(lab))
p <- ggplot(df, aes(x, y, label = z))
p + geom_textpath(vjust = -0.2, hjust = 0.1, size = 8, parse = TRUE) and ggplot() + xlim(0, 1) +
stat_function(fun = \(x) x, label = "paste('y = ', x)",
geom = "textpath", vjust = -0.2, parse = TRUE) +
stat_function(fun = \(x) x^2, label = "paste('y = ', x^2)",
geom = "textpath", vjust = -0.2, parse = TRUE) +
stat_function(fun = \(x) x^3, label = "paste('y = ', x^3)",
geom = "textpath", vjust = -0.2, parse = TRUE) |
The latest commit allows multiple parsed expressions and fixes some line spacing problems with the above implementation, so plotmath should have the same functionality as text. |
One of the things users will presumably want to do is to have expressions as textpaths. This isn't currently handled. A
textGrob
can take expressions, hencegeom_text
can parse text into expressions and pass them on directly totextGrob
. However, the rendering of expressions intextGrob
happens via C code inplotmath.c
, meaning that parsed expressions produce a single object that cannot be broken up and curved in the way that a text string can.There are a few ways to handle this
However, if we were going to go to the bother of doing this, the mechanism would also work for plain text, and we would be as well changing the entire implementation, which I really don't fancy doing.
The text was updated successfully, but these errors were encountered: