I want to fit a fairly long main title for a plot, supposedly by changing row after a while. As for now it starts way outside the picture margin at the left and continues way out right passed the right margins.>plot(A,main="This is my really long title and it's so long that I can seejust about half of it.") Any suggestions? Shouldn't be that hard. -- View this message in context: http://www.nabble.com/Fitting-large-titles-in-a-plot-tf4956510.html#a14193900 Sent from the R help mailing list archive at Nabble.com.
I wrote a little utility function for exactly this reason, which I use with long titles. You may want to add calls to par to adjust the upper margin if you are using raw graphical functionality (plot et al) - but lattice adjusts the upper margin automatically so you wouldn't need to add anything else. PrettyString <- function(theString, maxLength, collapse = "\n") { words <- unlist(strsplit(theString, " ")) wordLengths <- unlist(lapply(strsplit(words, ""), length)) if(max(wordLengths) > maxLength) stop("maxChar must be increased due to string length") count = wordLengths[1] results = vector() currentLine = words[1] for(i in 2:length(words)) { if((count + wordLengths[i] + 1) > maxLength) { results = c(results, currentLine) currentLine = words[i] count = wordLengths[i] } else { currentLine = paste(currentLine, words[i]) count = count + wordLengths[i] + 1 } } if(length(currentLine)) results <- c(results, currentLine) paste(results, collapse = collapse) } Knowing the R list, someone can probably reduce this function to 2 lines of code. Jim Svempa wrote:> > I want to fit a fairly long main title for a plot, supposedly by changing > row after a while. As for now it starts way outside the picture margin at > the left and continues way out right passed the right margins. > >>plot(A,main="This is my really long title and it's so long that I can seejust about half of it.")> > Any suggestions? Shouldn't be that hard. > >-- View this message in context: http://www.nabble.com/Fitting-large-titles-in-a-plot-tf4956510.html#a14196971 Sent from the R help mailing list archive at Nabble.com.
Try This: plot(A,main=paste("This is my really long title and","\n","it's so long that I can see just about half of it.", sep = " ")) -- Bert Gunter Genentech
Try inserting \n into the title where you would like it to start on a new line, e.g.: plot(A,main="This is my really long title\nand it's so long\nthat I can see just about half of it.") You may need to give yourself more room in the margin for multi-line titles (see ?par and the mar entry) and using the title function (rather than in the plot) will let you specify the position of the title (line argument). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Svempa > Sent: Thursday, December 06, 2007 8:16 AM > To: r-help at r-project.org > Subject: [R] Fitting large titles in a plot > > > I want to fit a fairly long main title for a plot, supposedly > by changing row after a while. As for now it starts way > outside the picture margin at the left and continues way out > right passed the right margins. > > >plot(A,main="This is my really long title and it's so long > that I can > >see > just about half of it.") > > Any suggestions? Shouldn't be that hard. > > -- > View this message in context: > http://www.nabble.com/Fitting-large-titles-in-a-plot-tf4956510 > .html#a14193900 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
\n to start a new line plot(1:10,main="This is my really long title \n and it's so long that I can see \n just about half of it.") --- Svempa <fempa at yahoo.com> wrote:> > I want to fit a fairly long main title for a plot, > supposedly by changing row > after a while. As for now it starts way outside the > picture margin at the > left and continues way out right passed the right > margins. > > >plot(A,main="This is my really long title and it's > so long that I can see > just about half of it.") > > Any suggestions? Shouldn't be that hard. > > -- > View this message in context: >http://www.nabble.com/Fitting-large-titles-in-a-plot-tf4956510.html#a14193900> Sent from the R help mailing list archive at > Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >
On Thu, 2007-12-06 at 07:16 -0800, Svempa wrote:> I want to fit a fairly long main title for a plot, supposedly by changing row > after a while. As for now it starts way outside the picture margin at the > left and continues way out right passed the right margins. > > >plot(A,main="This is my really long title and it's so long that I can see > just about half of it.") > > Any suggestions? Shouldn't be that hard.You can insert newline characters ('\n') in the title: plot(A, main = "This is my really long title\nand it's so long that I can see\njust about half of it.") The likelihood is that you will need to alter the vertical position of the title to accommodate the line wrapping. To do that, you can either use mtext() in lieu of the 'main' argument, or consider adjusting par("mgp"), the first value of which is the position of the plot title. See ?mtext and ?par. You might also want to look at ?strwrap for a more general way of wrapping long lines of text. HTH, Marc Schwartz
try this: plot(0, main=paste(strwrap("This is my really long title and it's so long that I can see just about half of it.", width=50), collapse="\n")) On Dec 6, 2007 7:16 AM, Svempa <fempa at yahoo.com> wrote:> > I want to fit a fairly long main title for a plot, supposedly by changing row > after a while. As for now it starts way outside the picture margin at the > left and continues way out right passed the right margins. > > >plot(A,main="This is my really long title and it's so long that I can see > just about half of it.") > > Any suggestions? Shouldn't be that hard. > > -- > View this message in context: http://www.nabble.com/Fitting-large-titles-in-a-plot-tf4956510.html#a14193900 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
On Thu, 06-Dec-2007 at 07:16AM -0800, Svempa wrote: |> |> I want to fit a fairly long main title for a plot, supposedly by changing row |> after a while. As for now it starts way outside the picture margin at the |> left and continues way out right passed the right margins. |> |> >plot(A,main="This is my really long title and it's so long that I can see |> just about half of it.") |> |> Any suggestions? Shouldn't be that hard. Something like this will probably be close enough: main="This is my really long title and it's so long that I can see\njust about half of it." HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Middle minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.