[R] italics letter in roman string

2007-03-17 Thread Chabot Denis
Hi,

As part of the legend to a plot, I need to have the "n" in italics  
because it is a requirement of the journal I aim to publish in:
"This study, n = 3293"

Presently I have:
legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
 pt.cex=0.3, cex=0.8, bty="n")

I suppose I could leave a blank in place of the "n", then issue a  
text call where I'd use font=3 for a single letter, "n". But it will  
be tricky to find the exact location to use.

Is there a way to switch to font=3 just for one letter within a string?

Thanks in advance,

Denis Chabot

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-17 Thread Marc Schwartz
On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
> Hi,
> 
> As part of the legend to a plot, I need to have the "n" in italics  
> because it is a requirement of the journal I aim to publish in:
> "This study, n = 3293"
> 
> Presently I have:
> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
>  pt.cex=0.3, cex=0.8, bty="n")
> 
> I suppose I could leave a blank in place of the "n", then issue a  
> text call where I'd use font=3 for a single letter, "n". But it will  
> be tricky to find the exact location to use.
> 
> Is there a way to switch to font=3 just for one letter within a string?
> 
> Thanks in advance,
> 
> Denis Chabot

Denis,

Try something like this:

plot(20, 100)

leg <- legend(20, 105, "This study,= 3293", pch = 1, 
  col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8, 
  bty = "n")

text(leg$text$x + strwidth("This study, ", cex = 0.8), 
 leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))


Note that legend returns a list structure, which contains the x and y
coordinates of the start of the text strings that are plotted. So I get
that information for your line of text.

Next, I use strwidth() to calculate, in user coordinates, the length of
the characters preceding the 'n', including spaces.  We add that
distance to the x coordinate returned in the legend call.

I also use the 'adj' argument in the text() call, so that it is in synch
with the same parameters in legend() for alignment with the other
letters.

See ?strwidth for more information.

You may have to tweak the horizontal spacing of the 'n' a bit, depending
upon the rest of your graph.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-17 Thread jim holtman
It is easier with:

legend('topleft', expression(paste("This study, ", italic(n) == 3295)))



On 3/17/07, Marc Schwartz <[EMAIL PROTECTED]> wrote:
>
> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
> > Hi,
> >
> > As part of the legend to a plot, I need to have the "n" in italics
> > because it is a requirement of the journal I aim to publish in:
> > "This study, n = 3293"
> >
> > Presently I have:
> > legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
> >  pt.cex=0.3, cex=0.8, bty="n")
> >
> > I suppose I could leave a blank in place of the "n", then issue a
> > text call where I'd use font=3 for a single letter, "n". But it will
> > be tricky to find the exact location to use.
> >
> > Is there a way to switch to font=3 just for one letter within a string?
> >
> > Thanks in advance,
> >
> > Denis Chabot
>
> Denis,
>
> Try something like this:
>
> plot(20, 100)
>
> leg <- legend(20, 105, "This study,= 3293", pch = 1,
>  col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
>  bty = "n")
>
> text(leg$text$x + strwidth("This study, ", cex = 0.8),
> leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
>
>
> Note that legend returns a list structure, which contains the x and y
> coordinates of the start of the text strings that are plotted. So I get
> that information for your line of text.
>
> Next, I use strwidth() to calculate, in user coordinates, the length of
> the characters preceding the 'n', including spaces.  We add that
> distance to the x coordinate returned in the legend call.
>
> I also use the 'adj' argument in the text() call, so that it is in synch
> with the same parameters in legend() for alignment with the other
> letters.
>
> See ?strwidth for more information.
>
> You may have to tweak the horizontal spacing of the 'n' a bit, depending
> upon the rest of your graph.
>
> HTH,
>
> Marc Schwartz
>
> __
> R-help@stat.math.ethz.ch 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?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-17 Thread Marc Schwartz
On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
> > Hi,
> > 
> > As part of the legend to a plot, I need to have the "n" in italics  
> > because it is a requirement of the journal I aim to publish in:
> > "This study, n = 3293"
> > 
> > Presently I have:
> > legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
> >  pt.cex=0.3, cex=0.8, bty="n")
> > 
> > I suppose I could leave a blank in place of the "n", then issue a  
> > text call where I'd use font=3 for a single letter, "n". But it will  
> > be tricky to find the exact location to use.
> > 
> > Is there a way to switch to font=3 just for one letter within a string?
> > 
> > Thanks in advance,
> > 
> > Denis Chabot
> 
> Denis,
> 
> Try something like this:
> 
> plot(20, 100)
> 
> leg <- legend(20, 105, "This study,= 3293", pch = 1, 
>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8, 
>   bty = "n")
> 
> text(leg$text$x + strwidth("This study, ", cex = 0.8), 
>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
> 
> 
> Note that legend returns a list structure, which contains the x and y
> coordinates of the start of the text strings that are plotted. So I get
> that information for your line of text.
> 
> Next, I use strwidth() to calculate, in user coordinates, the length of
> the characters preceding the 'n', including spaces.  We add that
> distance to the x coordinate returned in the legend call.
> 
> I also use the 'adj' argument in the text() call, so that it is in synch
> with the same parameters in legend() for alignment with the other
> letters.
> 
> See ?strwidth for more information.
> 
> You may have to tweak the horizontal spacing of the 'n' a bit, depending
> upon the rest of your graph.

Denis,

I thought of another approach, using plotmath.

First, create a text expression, specifying that the 'n' should be
italicized. Then use that expression in the legend() call.

txt <- expression(paste("This study, ", italic(n), " = 3293"))
 
plot(20, 100)

legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5), 
   pt.cex = 0.3, cex = 0.8, bty = "n")


That's easier that the first solution.  See ?plotmath

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-17 Thread Gabor Grothendieck
Try this:

plot(1:10)
legend("topleft", This ~ study ~ italic(n) == 3293)


On 3/17/07, Chabot Denis <[EMAIL PROTECTED]> wrote:
> Hi,
>
> As part of the legend to a plot, I need to have the "n" in italics
> because it is a requirement of the journal I aim to publish in:
> "This study, n = 3293"
>
> Presently I have:
> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
> pt.cex=0.3, cex=0.8, bty="n")
>
> I suppose I could leave a blank in place of the "n", then issue a
> text call where I'd use font=3 for a single letter, "n". But it will
> be tricky to find the exact location to use.
>
> Is there a way to switch to font=3 just for one letter within a string?
>
> Thanks in advance,
>
> Denis Chabot
>
> __
> R-help@stat.math.ethz.ch 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.
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-18 Thread Gabor Grothendieck
Sorry, legend= was omitted:

plot(1:10)
legend("topleft", legend = This ~ study ~ italic(n) == 3293)

On 3/18/07, Chabot Denis <[EMAIL PROTECTED]> wrote:
> Thank you Marc, Jim and Gabor,
>
> I like the solution with "expression", nice and simple. Gabor, your
> solution did not work, probably just a matter of putting the text
> inside an expression?
>
> However it would be nice if the help system pointed to it. A search
> on "italics" brought me nothing, one on "italic" gave me 4 hits, none
> useful. And reading the help on plotmath, I found no mention of italic
> (). Where can we suggest additions to the help system?
>
> I must plead guilty to have forgotten a RSiteSearch before posting. I
> just did and I think I might have figured out something out there.
> But your answers were nice and to the point!
>
> Cheers,
>
> Denis
> Le 07-03-17 à 23:30, Marc Schwartz a écrit :
>
> > On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
> >> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
> >>> Hi,
> >>>
> >>> As part of the legend to a plot, I need to have the "n" in italics
> >>> because it is a requirement of the journal I aim to publish in:
> >>> "This study, n = 3293"
> >>>
> >>> Presently I have:
> >>> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
> >>>  pt.cex=0.3, cex=0.8, bty="n")
> >>>
> >>> I suppose I could leave a blank in place of the "n", then issue a
> >>> text call where I'd use font=3 for a single letter, "n". But it will
> >>> be tricky to find the exact location to use.
> >>>
> >>> Is there a way to switch to font=3 just for one letter within a
> >>> string?
> >>>
> >>> Thanks in advance,
> >>>
> >>> Denis Chabot
> >>
> >> Denis,
> >>
> >> Try something like this:
> >>
> >> plot(20, 100)
> >>
> >> leg <- legend(20, 105, "This study,= 3293", pch = 1,
> >>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
> >>   bty = "n")
> >>
> >> text(leg$text$x + strwidth("This study, ", cex = 0.8),
> >>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
> >>
> >>
> >> Note that legend returns a list structure, which contains the x and y
> >> coordinates of the start of the text strings that are plotted. So
> >> I get
> >> that information for your line of text.
> >>
> >> Next, I use strwidth() to calculate, in user coordinates, the
> >> length of
> >> the characters preceding the 'n', including spaces.  We add that
> >> distance to the x coordinate returned in the legend call.
> >>
> >> I also use the 'adj' argument in the text() call, so that it is in
> >> synch
> >> with the same parameters in legend() for alignment with the other
> >> letters.
> >>
> >> See ?strwidth for more information.
> >>
> >> You may have to tweak the horizontal spacing of the 'n' a bit,
> >> depending
> >> upon the rest of your graph.
> >
> > Denis,
> >
> > I thought of another approach, using plotmath.
> >
> > First, create a text expression, specifying that the 'n' should be
> > italicized. Then use that expression in the legend() call.
> >
> > txt <- expression(paste("This study, ", italic(n), " = 3293"))
> >
> > plot(20, 100)
> >
> > legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5),
> >pt.cex = 0.3, cex = 0.8, bty = "n")
> >
> >
> > That's easier that the first solution.  See ?plotmath
> >
> > HTH,
> >
> > Marc Schwartz
> >
> >
>
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-18 Thread Chabot Denis
Thank you Marc, Jim and Gabor,

I like the solution with "expression", nice and simple. Gabor, your  
solution did not work, probably just a matter of putting the text  
inside an expression?

However it would be nice if the help system pointed to it. A search  
on "italics" brought me nothing, one on "italic" gave me 4 hits, none  
useful. And reading the help on plotmath, I found no mention of italic 
(). Where can we suggest additions to the help system?

I must plead guilty to have forgotten a RSiteSearch before posting. I  
just did and I think I might have figured out something out there.  
But your answers were nice and to the point!

Cheers,

Denis
Le 07-03-17 à 23:30, Marc Schwartz a écrit :

> On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
>> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
>>> Hi,
>>>
>>> As part of the legend to a plot, I need to have the "n" in italics
>>> because it is a requirement of the journal I aim to publish in:
>>> "This study, n = 3293"
>>>
>>> Presently I have:
>>> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
>>>  pt.cex=0.3, cex=0.8, bty="n")
>>>
>>> I suppose I could leave a blank in place of the "n", then issue a
>>> text call where I'd use font=3 for a single letter, "n". But it will
>>> be tricky to find the exact location to use.
>>>
>>> Is there a way to switch to font=3 just for one letter within a  
>>> string?
>>>
>>> Thanks in advance,
>>>
>>> Denis Chabot
>>
>> Denis,
>>
>> Try something like this:
>>
>> plot(20, 100)
>>
>> leg <- legend(20, 105, "This study,= 3293", pch = 1,
>>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
>>   bty = "n")
>>
>> text(leg$text$x + strwidth("This study, ", cex = 0.8),
>>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
>>
>>
>> Note that legend returns a list structure, which contains the x and y
>> coordinates of the start of the text strings that are plotted. So  
>> I get
>> that information for your line of text.
>>
>> Next, I use strwidth() to calculate, in user coordinates, the  
>> length of
>> the characters preceding the 'n', including spaces.  We add that
>> distance to the x coordinate returned in the legend call.
>>
>> I also use the 'adj' argument in the text() call, so that it is in  
>> synch
>> with the same parameters in legend() for alignment with the other
>> letters.
>>
>> See ?strwidth for more information.
>>
>> You may have to tweak the horizontal spacing of the 'n' a bit,  
>> depending
>> upon the rest of your graph.
>
> Denis,
>
> I thought of another approach, using plotmath.
>
> First, create a text expression, specifying that the 'n' should be
> italicized. Then use that expression in the legend() call.
>
> txt <- expression(paste("This study, ", italic(n), " = 3293"))
>
> plot(20, 100)
>
> legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5),
>pt.cex = 0.3, cex = 0.8, bty = "n")
>
>
> That's easier that the first solution.  See ?plotmath
>
> HTH,
>
> Marc Schwartz
>
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-18 Thread Chabot Denis
Wow, this works, Gabor, but I am mystified. I would have tought an  
expression needed the word expression, and/or a text string needed to  
be within quotes. What is happening here, exactly? Why the use of  
"~"? I tried without and it no longer works.

Thanks in advance,

Denis
Le 07-03-18 à 08:59, Gabor Grothendieck a écrit :

> Sorry, legend= was omitted:
>
> plot(1:10)
> legend("topleft", legend = This ~ study ~ italic(n) == 3293)
>
> On 3/18/07, Chabot Denis <[EMAIL PROTECTED]> wrote:
>> Thank you Marc, Jim and Gabor,
>>
>> I like the solution with "expression", nice and simple. Gabor, your
>> solution did not work, probably just a matter of putting the text
>> inside an expression?
>>
>> However it would be nice if the help system pointed to it. A search
>> on "italics" brought me nothing, one on "italic" gave me 4 hits, none
>> useful. And reading the help on plotmath, I found no mention of  
>> italic
>> (). Where can we suggest additions to the help system?
>>
>> I must plead guilty to have forgotten a RSiteSearch before posting. I
>> just did and I think I might have figured out something out there.
>> But your answers were nice and to the point!
>>
>> Cheers,
>>
>> Denis
>> Le 07-03-17 à 23:30, Marc Schwartz a écrit :
>>
>> > On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
>> >> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
>> >>> Hi,
>> >>>
>> >>> As part of the legend to a plot, I need to have the "n" in  
>> italics
>> >>> because it is a requirement of the journal I aim to publish in:
>> >>> "This study, n = 3293"
>> >>>
>> >>> Presently I have:
>> >>> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb 
>> (0,0,0,0.5),
>> >>>  pt.cex=0.3, cex=0.8, bty="n")
>> >>>
>> >>> I suppose I could leave a blank in place of the "n", then issue a
>> >>> text call where I'd use font=3 for a single letter, "n". But  
>> it will
>> >>> be tricky to find the exact location to use.
>> >>>
>> >>> Is there a way to switch to font=3 just for one letter within a
>> >>> string?
>> >>>
>> >>> Thanks in advance,
>> >>>
>> >>> Denis Chabot
>> >>
>> >> Denis,
>> >>
>> >> Try something like this:
>> >>
>> >> plot(20, 100)
>> >>
>> >> leg <- legend(20, 105, "This study,= 3293", pch = 1,
>> >>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
>> >>   bty = "n")
>> >>
>> >> text(leg$text$x + strwidth("This study, ", cex = 0.8),
>> >>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
>> >>
>> >>
>> >> Note that legend returns a list structure, which contains the x  
>> and y
>> >> coordinates of the start of the text strings that are plotted. So
>> >> I get
>> >> that information for your line of text.
>> >>
>> >> Next, I use strwidth() to calculate, in user coordinates, the
>> >> length of
>> >> the characters preceding the 'n', including spaces.  We add that
>> >> distance to the x coordinate returned in the legend call.
>> >>
>> >> I also use the 'adj' argument in the text() call, so that it is in
>> >> synch
>> >> with the same parameters in legend() for alignment with the other
>> >> letters.
>> >>
>> >> See ?strwidth for more information.
>> >>
>> >> You may have to tweak the horizontal spacing of the 'n' a bit,
>> >> depending
>> >> upon the rest of your graph.
>> >
>> > Denis,
>> >
>> > I thought of another approach, using plotmath.
>> >
>> > First, create a text expression, specifying that the 'n' should be
>> > italicized. Then use that expression in the legend() call.
>> >
>> > txt <- expression(paste("This study, ", italic(n), " = 3293"))
>> >
>> > plot(20, 100)
>> >
>> > legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5),
>> >pt.cex = 0.3, cex = 0.8, bty = "n")
>> >
>> >
>> > That's easier that the first solution.  See ?plotmath
>> >
>> > HTH,
>> >
>> > Marc Schwartz
>> >
>> >
>>
>>

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-18 Thread Gabor Grothendieck
Its a formula, not an expression -- but it will coerce formulas.  Without ~
its no longer a formula.

On 3/18/07, Chabot Denis <[EMAIL PROTECTED]> wrote:
> Wow, this works, Gabor, but I am mystified. I would have tought an
> expression needed the word expression, and/or a text string needed to
> be within quotes. What is happening here, exactly? Why the use of
> "~"? I tried without and it no longer works.
>
> Thanks in advance,
>
> Denis
> Le 07-03-18 à 08:59, Gabor Grothendieck a écrit :
>
> > Sorry, legend= was omitted:
> >
> > plot(1:10)
> > legend("topleft", legend = This ~ study ~ italic(n) == 3293)
> >
> > On 3/18/07, Chabot Denis <[EMAIL PROTECTED]> wrote:
> >> Thank you Marc, Jim and Gabor,
> >>
> >> I like the solution with "expression", nice and simple. Gabor, your
> >> solution did not work, probably just a matter of putting the text
> >> inside an expression?
> >>
> >> However it would be nice if the help system pointed to it. A search
> >> on "italics" brought me nothing, one on "italic" gave me 4 hits, none
> >> useful. And reading the help on plotmath, I found no mention of
> >> italic
> >> (). Where can we suggest additions to the help system?
> >>
> >> I must plead guilty to have forgotten a RSiteSearch before posting. I
> >> just did and I think I might have figured out something out there.
> >> But your answers were nice and to the point!
> >>
> >> Cheers,
> >>
> >> Denis
> >> Le 07-03-17 à 23:30, Marc Schwartz a écrit :
> >>
> >> > On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
> >> >> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
> >> >>> Hi,
> >> >>>
> >> >>> As part of the legend to a plot, I need to have the "n" in
> >> italics
> >> >>> because it is a requirement of the journal I aim to publish in:
> >> >>> "This study, n = 3293"
> >> >>>
> >> >>> Presently I have:
> >> >>> legend(20, 105, "This study, n = 3293", pch=1,  col=rgb
> >> (0,0,0,0.5),
> >> >>>  pt.cex=0.3, cex=0.8, bty="n")
> >> >>>
> >> >>> I suppose I could leave a blank in place of the "n", then issue a
> >> >>> text call where I'd use font=3 for a single letter, "n". But
> >> it will
> >> >>> be tricky to find the exact location to use.
> >> >>>
> >> >>> Is there a way to switch to font=3 just for one letter within a
> >> >>> string?
> >> >>>
> >> >>> Thanks in advance,
> >> >>>
> >> >>> Denis Chabot
> >> >>
> >> >> Denis,
> >> >>
> >> >> Try something like this:
> >> >>
> >> >> plot(20, 100)
> >> >>
> >> >> leg <- legend(20, 105, "This study,= 3293", pch = 1,
> >> >>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
> >> >>   bty = "n")
> >> >>
> >> >> text(leg$text$x + strwidth("This study, ", cex = 0.8),
> >> >>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
> >> >>
> >> >>
> >> >> Note that legend returns a list structure, which contains the x
> >> and y
> >> >> coordinates of the start of the text strings that are plotted. So
> >> >> I get
> >> >> that information for your line of text.
> >> >>
> >> >> Next, I use strwidth() to calculate, in user coordinates, the
> >> >> length of
> >> >> the characters preceding the 'n', including spaces.  We add that
> >> >> distance to the x coordinate returned in the legend call.
> >> >>
> >> >> I also use the 'adj' argument in the text() call, so that it is in
> >> >> synch
> >> >> with the same parameters in legend() for alignment with the other
> >> >> letters.
> >> >>
> >> >> See ?strwidth for more information.
> >> >>
> >> >> You may have to tweak the horizontal spacing of the 'n' a bit,
> >> >> depending
> >> >> upon the rest of your graph.
> >> >
> >> > Denis,
> >> >
> >> > I thought of another approach, using plotmath.
> >> >
> >> > First, create a text expression, specifying that the 'n' should be
> >> > italicized. Then use that expression in the legend() call.
> >> >
> >> > txt <- expression(paste("This study, ", italic(n), " = 3293"))
> >> >
> >> > plot(20, 100)
> >> >
> >> > legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5),
> >> >pt.cex = 0.3, cex = 0.8, bty = "n")
> >> >
> >> >
> >> > That's easier that the first solution.  See ?plotmath
> >> >
> >> > HTH,
> >> >
> >> > Marc Schwartz
> >> >
> >> >
> >>
> >>
>
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] italics letter in roman string

2007-03-18 Thread Duncan Murdoch
On 3/18/2007 8:56 AM, Chabot Denis wrote:
> Thank you Marc, Jim and Gabor,
> 
> I like the solution with "expression", nice and simple. Gabor, your  
> solution did not work, probably just a matter of putting the text  
> inside an expression?
> 
> However it would be nice if the help system pointed to it. A search  
> on "italics" brought me nothing, one on "italic" gave me 4 hits, none  
> useful. And reading the help on plotmath, I found no mention of italic 
> (). Where can we suggest additions to the help system?

The R-devel list is the best place to make suggestions like that if 
you're talking about documentation in base packages.  Please submit 
patches to the source from

https://svn.r-project.org/R/trunk

Package documentation is in src/library/*/man/*.Rd, the manuals are in 
doc/manual/*.texi.  There are also bits and pieces of other 
documentation (FAQs, etc.) elsewhere.

Suggestions about contributed packages (including Recommended ones) 
should be sent to the package maintainer and/or author.

Duncan Murdoch

> 
> I must plead guilty to have forgotten a RSiteSearch before posting. I  
> just did and I think I might have figured out something out there.  
> But your answers were nice and to the point!
> 
> Cheers,
> 
> Denis
> Le 07-03-17 à 23:30, Marc Schwartz a écrit :
> 
>> On Sat, 2007-03-17 at 21:56 -0500, Marc Schwartz wrote:
>>> On Sat, 2007-03-17 at 22:01 -0400, Chabot Denis wrote:
 Hi,

 As part of the legend to a plot, I need to have the "n" in italics
 because it is a requirement of the journal I aim to publish in:
 "This study, n = 3293"

 Presently I have:
 legend(20, 105, "This study, n = 3293", pch=1,  col=rgb(0,0,0,0.5),
  pt.cex=0.3, cex=0.8, bty="n")

 I suppose I could leave a blank in place of the "n", then issue a
 text call where I'd use font=3 for a single letter, "n". But it will
 be tricky to find the exact location to use.

 Is there a way to switch to font=3 just for one letter within a  
 string?

 Thanks in advance,

 Denis Chabot
>>> Denis,
>>>
>>> Try something like this:
>>>
>>> plot(20, 100)
>>>
>>> leg <- legend(20, 105, "This study,= 3293", pch = 1,
>>>   col=rgb(0,0,0,0.5), pt.cex = 0.3, cex = 0.8,
>>>   bty = "n")
>>>
>>> text(leg$text$x + strwidth("This study, ", cex = 0.8),
>>>  leg$text$y, "n", font = 3, cex = 0.8, adj = c(0, 0.5))
>>>
>>>
>>> Note that legend returns a list structure, which contains the x and y
>>> coordinates of the start of the text strings that are plotted. So  
>>> I get
>>> that information for your line of text.
>>>
>>> Next, I use strwidth() to calculate, in user coordinates, the  
>>> length of
>>> the characters preceding the 'n', including spaces.  We add that
>>> distance to the x coordinate returned in the legend call.
>>>
>>> I also use the 'adj' argument in the text() call, so that it is in  
>>> synch
>>> with the same parameters in legend() for alignment with the other
>>> letters.
>>>
>>> See ?strwidth for more information.
>>>
>>> You may have to tweak the horizontal spacing of the 'n' a bit,  
>>> depending
>>> upon the rest of your graph.
>> Denis,
>>
>> I thought of another approach, using plotmath.
>>
>> First, create a text expression, specifying that the 'n' should be
>> italicized. Then use that expression in the legend() call.
>>
>> txt <- expression(paste("This study, ", italic(n), " = 3293"))
>>
>> plot(20, 100)
>>
>> legend(20, 105, txt, pch = 1, col=rgb(0,0,0,0.5),
>>pt.cex = 0.3, cex = 0.8, bty = "n")
>>
>>
>> That's easier that the first solution.  See ?plotmath
>>
>> HTH,
>>
>> Marc Schwartz
>>
>>
> 
> __
> R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.