Skip to content

Formatting names.arg

5 messages · Adrienne Keller, Marc Schwartz, Ben Bolker +1 more

#
On May 23, 2011, at 3:13 PM, Adrienne Keller wrote:

            
Hi,

Just replace the space between the names with a newline character ('\n'):

  barplot(1:9, names.arg = gsub(" ", "\\\n", speciesnames), 
          cex.names = 0.5)

That will put the labels on two lines.

See ?gsub and note that I used 3 '\' preceding the 'n'.

HTH,

Marc Schwartz
#
Adrienne Keller <adrienne.keller <at> umontana.edu> writes:
[snip]


  Try "Dialium\nguianensis" etc. ?
#
On May 23, 2011, at 4:32 PM, Marc Schwartz wrote:

            
Except that tripling of "\" is not necessary with the second argument  
to gsub or sub, only with the first pattern argument.

  speciesnames<-c("Dialium guianensis", "Inga alba", "Tachigali  
versicolor", "Brosimum utile", "Caryocar costaricense", "Castilla  
tunu", "Otoba novagranatensis", "Pourouma bicolor", "Socratea  
exorrhiza")

sub(" ", "\n", speciesnames)

[1] "Dialium\nguianensis"    "Inga\nalba"
[3] "Tachigali\nversicolor"  "Brosimum\nutile"
[5] "Caryocar\ncostaricense" "Castilla\ntunu"
[7] "Otoba\nnovagranatensis" "Pourouma\nbicolor"
[9] "Socratea\nexorrhiza"
#
On May 23, 2011, at 4:31 PM, David Winsemius wrote:

            
Thanks for catching that David, you are correct. That's what I get for answering the post in the middle of formatting R output for LaTeX and having tunnel vision on the backslashes...

:-)

Regards,

Marc