How to divide too long labels?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to divide too long labels?

Atte Tenkanen
Is there any possibility to divide too long text in a plot to two or more
lines, when using labels-parameter in the text()-command?

Here is an example picture:

http://users.utu.fi/attenka/253.jpeg

My example script is something like this:

text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry
Solomon's table http://solomonsmusic.net/pcsets.htm

Chordnames is a long vector with long character strings.

Atte Tenkanen
University of Turku
Finland

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to divide too long labels?

Roger Bivand
On Sat, 18 Mar 2006, Atte Tenkanen wrote:

> Is there any possibility to divide too long text in a plot to two or more
> lines, when using labels-parameter in the text()-command?
>
> Here is an example picture:
>
> http://users.utu.fi/attenka/253.jpeg
>
> My example script is something like this:
>
> text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry
> Solomon's table http://solomonsmusic.net/pcsets.htm
>
> Chordnames is a long vector with long character strings.

I think you could pre-process the labels column to insert suitable line
breaks:

str <- "Pantuvarali Raga (1321131), Chromatic Mixolydian (1131132), Chromatic Dorian/Mela Kanakangi (1132113)"
out <- paste(strwrap(str, width=40), collapse="\n")

but I think you'd have to do it for each value separately.

>
> Atte Tenkanen
> University of Turku
> Finland
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: How to divide too long labels?

Henrik Bengtsson-2
In reply to this post by Atte Tenkanen
On 3/18/06, Atte Tenkanen <[hidden email]> wrote:

> Is there any possibility to divide too long text in a plot to two or more
> lines, when using labels-parameter in the text()-command?
>
> Here is an example picture:
>
> http://users.utu.fi/attenka/253.jpeg
>
> My example script is something like this:
>
> text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry
> Solomon's table http://solomonsmusic.net/pcsets.htm
>
> Chordnames is a long vector with long character strings.

plot(1, xlab="First row\nSecond row")
text(1,1, labels="First row\nSecond row")

To insert a '\n' at sensible positions such as between two words, look
at regexpr() and substring() and paste(). If you labels have a known
pattern you might be able to use gsub().

/Henrik

> Atte Tenkanen
> University of Turku
> Finland
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>


--
Henrik Bengtsson
Mobile: +46 708 909208 (+1h UTC)

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to divide too long labels?

Atte Tenkanen
Thank you for answering, both Roger and Henrik

There are only 5 cases which need divisions, so I inserted \n to them and
now everything works.

Atte

> On 3/18/06, Atte Tenkanen <[hidden email]> wrote:
>> Is there any possibility to divide too long text in a plot to two or
>> more
>> lines, when using labels-parameter in the text()-command?
>>
>> Here is an example picture:
>>
>> http://users.utu.fi/attenka/253.jpeg
>>
>> My example script is something like this:
>>
>> text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry
>> Solomon's table http://solomonsmusic.net/pcsets.htm
>>
>> Chordnames is a long vector with long character strings.
>
> plot(1, xlab="First row\nSecond row")
> text(1,1, labels="First row\nSecond row")
>
> To insert a '\n' at sensible positions such as between two words, look
> at regexpr() and substring() and paste(). If you labels have a known
> pattern you might be able to use gsub().
>
> /Henrik
>
>> Atte Tenkanen
>> University of Turku
>> Finland
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>>
>
>
> --
> Henrik Bengtsson
> Mobile: +46 708 909208 (+1h UTC)
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html