Open kaushalmodi opened 3 years ago
Hey! Great to hear from you. :)
That's a good point. I've thought about this myself sometimes. I just wasn't sure if breaking the line is the most desired behavior. That is mainly because of the amount of space in the header part by default.
I've already implemented manual line wrapping support for the annotations. So it shouldn't be too hard to apply this here. Auto wrapping should also be possible, because I can determine the width of a string on a given viewport. I suppose I could break at the last space before the width is exceeded.
I'll give this a try! Don't want to make any promises, but I'll put it into the PR that's been open for a week or so (plus some other stuff I have sitting locally already). Sometime next week at the latest.
Finally gave it a try to implement this morning. Was indeed pretty easy.
The only thing I did not implement (because I think it's not desired behavior by default) is to extend the region of the header to accommodate multiple lines. So in case one expects multiple lines in the header, it's required to either set a smaller font thane the default (using the titleFont
argument of ggtitle
) or increase the header region's size using margin(top = <some value in cm>")
.
I'll push this to the PR now.
See the recipe here: https://github.com/Vindaar/ggplotnim/blob/master/recipes.org#plot-with-a-title-including-line-breaks
Thanks! I will try this out today and let you know.
Looking at your example (and I know you said that I need to specify the margin manually), one minor suggestion would be to auto-increase the margin as needed. The reason is that I am dynamically creating the title, and probably margin=2 will work for most cases. Just in case only margin=1 is enough, or if more lines are needed, can ggplotnim figure that out automatically?
one minor suggestion would be to auto-increase the margin as needed
I thought about that. In principle I can do that fine. The reason why I decided against it is because by increasing the margin I have to do one of two things:
Now that you mention it however, it would probably be a good idea to allow auto resizing by supplying an argument to the ggtitle
procedure. I'll implement that in the next few days!
I updated ggplotnim from HEAD and I confirm the auto-wrapping and margin option. Thanks!
For now, I will start using margin=2 for my plots. But if the auto-margin works out, it would be great! :)
Hello,
I was just using this package to dynamically construct the plot titles and often the titles would get longer than the image widths and get truncated. Here's a simple example using the first example in the recipe.org:
This will create
This is using the latest release of ggplotnim, 0.3.18.
I tried using
\n
and\\n
in the string passed toggtitle
but that didn't work.Can you enable auto-wrapping of the title, and/or allow a way to insert newlines in the title?
Thanks!