Re: [R] using a variable and a superscript in a legend

2019-10-20 Thread Peter Dalgaard
You're right. I was worried that c() would create a character vector and 
deparse the unevaluated call in the process, but apparently it is an implicit 
as.character _inside_ legend that is doing us in. (I can't offhand see where it 
is happening, but there might be scope for improvement if legend() would just 
accept a list object and treat the elements separately).

-pd

> On 20 Oct 2019, at 20:28 , Bert Gunter  wrote:
> 
> However, note that:
> 
> > class(c("Sans renard", bquote(.(densren) (ind./km)^2)))
> [1] "list"  # by coercion
> 
> so it does not seem necessary to explicitly call list(). That is:
> 
>plot(1:100,1:100,type="n")
>legend(list(x=0,y=100), legend = as.expression(c("Sans renard", 
> bquote(.(densren) (ind./km)^2))),lty=c(1,2),col=c("black","red"),bty="n")
> 
> appears to suffice. I would appreciate correction if I'm wrong about this.
> 

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Bert Gunter
To continue down this rabbit hole ...

Actually, both solutions are the same; Peter's is just more general than
mine, as it works more conveniently for more lines in the legend.

However, note that:

> class(c("Sans renard", bquote(.(densren) (ind./km)^2)))
[1] "list"  # by coercion

so it does not seem necessary to explicitly call list(). That is:

   plot(1:100,1:100,type="n")
   legend(list(x=0,y=100), legend = as.expression(c("Sans renard",
bquote(.(densren) (ind./km)^2))),lty=c(1,2),col=c("black","red"),bty="n")

appears to suffice. I would appreciate correction if I'm wrong about this.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 20, 2019 at 11:01 AM Patrick Giraudoux <
patrick.giraud...@univ-fcomte.fr> wrote:

> Now, we have two solutions working. This is great since I did not find
> any example of the kind searching r-help archives and google...
> Thanks !
>
> Le 20/10/2019 à 19:31, Peter Dalgaard a écrit :
> > It's tricky, but I think what you want is
> >
> > legend(list(x=0,y=100),
> > legend=as.expression(list(
> >   "Sans renard",
> >   bquote(.(densren) * " ind."/"km"^2)
> > )),
> > lty=c(1,2),col=c("black","red"),bty="n")
> >
> > Generally, if you want a vector of unevaluated expressions, you need an
> object of mode "expression", but you cannot create it directly with
> expression() because then the bquote() is left unevaluated:
> >
> >> expression("Sans renard",bquote(.(densren) * " ind."/"km"^2))
> > expression("Sans renard", bquote(.(densren) * " ind."/"km"^2))
> >
> > Putting the bquote on the outside _looks_ like it might work:
> >
> >> bquote(expression("Sans renard",.(densren) * " ind."/"km"^2))
> > expression("Sans renard", 1.25 * " ind."/"km"^2)
> >
> > but that is not an "expression" object, but a call to expression() (!).
> Try it and see.
> >
> > Evaluating the call does actually work (notice that the printed value is
> exactly the same, but the object is not):
> >
> >> eval(bquote(expression("Sans renard",.(densren) * " ind."/"km"^2)))
> > expression("Sans renard", 1.25 * " ind."/"km"^2)
> >
> > but I think I prefer the as.expression(list()) construction.
> >
> > An alternative tack is this:
> >
> >> e <- expression(0,0)
> >> e[[1]] <- "sans renard"
> >> e[[2]] <- bquote(.(densren) * " ind."/"km"^2)
> >> plot(1:100,1:100,type="n")
> >> legend(list(x=0,y=100),legend=e,
> lty=c(1,2),col=c("black","red"),bty="n")
> >
> >
> >> On 20 Oct 2019, at 18:02 , Patrick Giraudoux <
> patrick.giraud...@univ-fcomte.fr> wrote:
> >>
> >> Thanks Bert and Peter,
> >>
> >> Yes Bert, I was aware of the legend() function syntax, and just quoting
> the legend argument within the function.
> >>
> >> However, Bert and Peter, I do not understand why it works with your
> absolutely reproducible examples and not in the slightly (not so slightly
> apparently) different context where I used it...
> >>
> >> densren=1.25
> >> plot(1:100,1:100,type="n")
> >> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren)
> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
> >>
> >> densren=1.25
> >> plot(1:100,1:100,type="n")
> >> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) * "
> ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"
> >>
> >> Probably because the result of bquote() is concatenated in a character
> vector, but how to deal with this ?
> >>
> >> Best,
> >>
> >> Patrick
> >>
> >>
> >>
> >> Le 20/10/2019 à 16:42, Bert Gunter a écrit :
> >>> Assuming you are using base graphics, your syntax for adding the
> legend appears to be wrong.
> >>> legend() is a separate function, not a parameter of plot.default
> afaics.
> >>>
> >>> The following works for me:
> >>>
>  densren <- 1.25
>  plot(1:10)
>  legend (x="center", legend =bquote(.(densren) (ind./km)^2))
> >>> See ?legend
> >>>
> >>> Bert Gunter
> >>>
> >>> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>>
> >>>
> >>> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux <
> patrick.giraud...@univ-fcomte.fr> wrote:
> >>> Dear listers,
> >>>
> >>> I am trying to pass an expression inlcuding a variable and a
> >>> superpscript to a legend. What I want to obtain is e.g. with densren =
> 1.25
> >>>
> >>> 1.25 ind./km^2
> >>>
> >>> I have tried many variants of the following:
> >>>
> >>> legend=bquote(.(densren) (ind./km)^2)
> >>>
> >>> but if not errors, do obtain
> >>>
> >>> 1.25 (ind./km^2)
> >>>
> >>> hence not what I want (no parenthesis, 2 in superscript...)
> >>>
> >>> Any idea about a correct syntax to get what I need ?
> >>>
> >>> Best,
> >>>
> >>> Patrick
> >>>
> >>>
> >>>  [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> 

Re: [R] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux


Would be nice to put those two way examples in the documentation of the 
function 'expression' and 'bquote' in the next R version (we are in the 
base) for other users  ;-) I am sure many would enjoy.



Le 20/10/2019 à 19:15, Patrick Giraudoux a écrit :
> Great !  You have helped to solve a problem on which I was sweating 
> (sporadically, however) since months...
>
> Thanks,
>
> Best,
>
>
> Le 20/10/2019 à 18:29, Bert Gunter a écrit :
>> The legend must be "an expression vector."
>> c("Sans renard",bquote(.(densren) (ind./km)^2))   is not because the 
>> first element is a character string.
>>
>> This works:
>>
>> plot(1:100,1:100,type="n")
>>    legend(list(x=0,y=100),legend=c(expression("Sans 
>> renard"),bquote(.(densren) 
>> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
>>
>> Cheers,
>> Bert
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming 
>> along and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Sun, Oct 20, 2019 at 9:02 AM Patrick Giraudoux 
>> > > wrote:
>>
>> Thanks Bert and Peter,
>>
>> Yes Bert, I was aware of the legend() function syntax, and just
>> quoting the legend argument within the function.
>>
>> However, Bert and Peter, I do not understand why it works with
>> your absolutely reproducible examples and not in the slightly
>> (not so slightly apparently) different context where I used it...
>>
>> densren=1.25
>> plot(1:100,1:100,type="n")
>> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren)
>> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
>>
>> densren=1.25
>> plot(1:100,1:100,type="n")
>> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) *
>> " ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"
>>
>> Probably because the result of bquote() is concatenated in a
>> character vector, but how to deal with this ?
>>
>> Best,
>>
>> Patrick
>>
>>
>>
>> Le 20/10/2019 à 16:42, Bert Gunter a écrit :
>>> Assuming you are using base graphics, your syntax for adding the
>>> legend appears to be wrong.
>>> legend() is a separate function, not a parameter of plot.default
>>> afaics.
>>>
>>> The following works for me:
>>>
>>> > densren <- 1.25
>>> > plot(1:10)
>>> > legend (x="center", legend =bquote(.(densren) (ind./km)^2))
>>>
>>> See ?legend
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming
>>> along and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux
>>> >> > wrote:
>>>
>>> Dear listers,
>>>
>>> I am trying to pass an expression inlcuding a variable and a
>>> superpscript to a legend. What I want to obtain is e.g. with
>>> densren = 1.25
>>>
>>> 1.25 ind./km^2
>>>
>>> I have tried many variants of the following:
>>>
>>> legend=bquote(.(densren) (ind./km)^2)
>>>
>>> but if not errors, do obtain
>>>
>>> 1.25 (ind./km^2)
>>>
>>> hence not what I want (no parenthesis, 2 in superscript...)
>>>
>>> Any idea about a correct syntax to get what I need ?
>>>
>>> Best,
>>>
>>> Patrick
>>>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org  mailing
>>> list -- To UNSUBSCRIBE and more, see
>>> 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.
>>>
>>
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux
Now, we have two solutions working. This is great since I did not find 
any example of the kind searching r-help archives and google...

Thanks !

Le 20/10/2019 à 19:31, Peter Dalgaard a écrit :

It's tricky, but I think what you want is

legend(list(x=0,y=100),
legend=as.expression(list(
  "Sans renard",
  bquote(.(densren) * " ind."/"km"^2)
)),
lty=c(1,2),col=c("black","red"),bty="n")

Generally, if you want a vector of unevaluated expressions, you need an object of mode 
"expression", but you cannot create it directly with expression() because then 
the bquote() is left unevaluated:


expression("Sans renard",bquote(.(densren) * " ind."/"km"^2))

expression("Sans renard", bquote(.(densren) * " ind."/"km"^2))

Putting the bquote on the outside _looks_ like it might work:


bquote(expression("Sans renard",.(densren) * " ind."/"km"^2))

expression("Sans renard", 1.25 * " ind."/"km"^2)

but that is not an "expression" object, but a call to expression() (!). Try it 
and see.

Evaluating the call does actually work (notice that the printed value is 
exactly the same, but the object is not):


eval(bquote(expression("Sans renard",.(densren) * " ind."/"km"^2)))

expression("Sans renard", 1.25 * " ind."/"km"^2)

but I think I prefer the as.expression(list()) construction.

An alternative tack is this:


e <- expression(0,0)
e[[1]] <- "sans renard"
e[[2]] <- bquote(.(densren) * " ind."/"km"^2)
plot(1:100,1:100,type="n")
legend(list(x=0,y=100),legend=e, lty=c(1,2),col=c("black","red"),bty="n")




On 20 Oct 2019, at 18:02 , Patrick Giraudoux  
wrote:

Thanks Bert and Peter,

Yes Bert, I was aware of the legend() function syntax, and just quoting the 
legend argument within the function.

However, Bert and Peter, I do not understand why it works with your absolutely 
reproducible examples and not in the slightly (not so slightly apparently) 
different context where I used it...

densren=1.25
plot(1:100,1:100,type="n")
legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) 
(ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")

densren=1.25
plot(1:100,1:100,type="n")
legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) * " 
ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"

Probably because the result of bquote() is concatenated in a character vector, 
but how to deal with this ?

Best,

Patrick



Le 20/10/2019 à 16:42, Bert Gunter a écrit :

Assuming you are using base graphics, your syntax for adding the legend appears 
to be wrong.
legend() is a separate function, not a parameter of plot.default afaics.

The following works for me:


densren <- 1.25
plot(1:10)
legend (x="center", legend =bquote(.(densren) (ind./km)^2))

See ?legend

Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking 
things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux 
 wrote:
Dear listers,

I am trying to pass an expression inlcuding a variable and a
superpscript to a legend. What I want to obtain is e.g. with densren = 1.25

1.25 ind./km^2

I have tried many variants of the following:

legend=bquote(.(densren) (ind./km)^2)

but if not errors, do obtain

1.25 (ind./km^2)

hence not what I want (no parenthesis, 2 in superscript...)

Any idea about a correct syntax to get what I need ?

Best,

Patrick


 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Peter Dalgaard
It's tricky, but I think what you want is

legend(list(x=0,y=100),
   legend=as.expression(list(
 "Sans renard",
 bquote(.(densren) * " ind."/"km"^2)
   )),
   lty=c(1,2),col=c("black","red"),bty="n")

Generally, if you want a vector of unevaluated expressions, you need an object 
of mode "expression", but you cannot create it directly with expression() 
because then the bquote() is left unevaluated:

> expression("Sans renard",bquote(.(densren) * " ind."/"km"^2))
expression("Sans renard", bquote(.(densren) * " ind."/"km"^2))

Putting the bquote on the outside _looks_ like it might work:

> bquote(expression("Sans renard",.(densren) * " ind."/"km"^2))
expression("Sans renard", 1.25 * " ind."/"km"^2)

but that is not an "expression" object, but a call to expression() (!). Try it 
and see.

Evaluating the call does actually work (notice that the printed value is 
exactly the same, but the object is not):

> eval(bquote(expression("Sans renard",.(densren) * " ind."/"km"^2)))
expression("Sans renard", 1.25 * " ind."/"km"^2)

but I think I prefer the as.expression(list()) construction.

An alternative tack is this:

> e <- expression(0,0)
> e[[1]] <- "sans renard"
> e[[2]] <- bquote(.(densren) * " ind."/"km"^2)
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=e, lty=c(1,2),col=c("black","red"),bty="n")



> On 20 Oct 2019, at 18:02 , Patrick Giraudoux 
>  wrote:
> 
> Thanks Bert and Peter,
> 
> Yes Bert, I was aware of the legend() function syntax, and just quoting the 
> legend argument within the function. 
> 
> However, Bert and Peter, I do not understand why it works with your 
> absolutely reproducible examples and not in the slightly (not so slightly 
> apparently) different context where I used it...
> 
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) 
> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
> 
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) * " 
> ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"
> 
> Probably because the result of bquote() is concatenated in a character 
> vector, but how to deal with this ?
> 
> Best,
> 
> Patrick
> 
> 
> 
> Le 20/10/2019 à 16:42, Bert Gunter a écrit :
>> Assuming you are using base graphics, your syntax for adding the legend 
>> appears to be wrong.
>> legend() is a separate function, not a parameter of plot.default afaics.
>> 
>> The following works for me:
>> 
>> > densren <- 1.25
>> > plot(1:10)
>> > legend (x="center", legend =bquote(.(densren) (ind./km)^2))
>> 
>> See ?legend
>> 
>> Bert Gunter
>> 
>> "The trouble with having an open mind is that people keep coming along and 
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> 
>> 
>> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux 
>>  wrote:
>> Dear listers,
>> 
>> I am trying to pass an expression inlcuding a variable and a 
>> superpscript to a legend. What I want to obtain is e.g. with densren = 1.25
>> 
>> 1.25 ind./km^2
>> 
>> I have tried many variants of the following:
>> 
>> legend=bquote(.(densren) (ind./km)^2)
>> 
>> but if not errors, do obtain
>> 
>> 1.25 (ind./km^2)
>> 
>> hence not what I want (no parenthesis, 2 in superscript...)
>> 
>> Any idea about a correct syntax to get what I need ?
>> 
>> Best,
>> 
>> Patrick
>> 
>> 
>> [[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
> 
> 

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux
Great !  You have helped to solve a problem on which I was sweating 
(sporadically, however) since months...

Thanks,

Best,


Le 20/10/2019 à 18:29, Bert Gunter a écrit :
> The legend must be "an expression vector."
> c("Sans renard",bquote(.(densren) (ind./km)^2))   is not because the 
> first element is a character string.
>
> This works:
>
> plot(1:100,1:100,type="n")
>    legend(list(x=0,y=100),legend=c(expression("Sans 
> renard"),bquote(.(densren) 
> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Oct 20, 2019 at 9:02 AM Patrick Giraudoux 
>  > wrote:
>
> Thanks Bert and Peter,
>
> Yes Bert, I was aware of the legend() function syntax, and just
> quoting the legend argument within the function.
>
> However, Bert and Peter, I do not understand why it works with
> your absolutely reproducible examples and not in the slightly (not
> so slightly apparently) different context where I used it...
>
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren)
> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
>
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) *
> " ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"
>
> Probably because the result of bquote() is concatenated in a
> character vector, but how to deal with this ?
>
> Best,
>
> Patrick
>
>
>
> Le 20/10/2019 à 16:42, Bert Gunter a écrit :
>> Assuming you are using base graphics, your syntax for adding the
>> legend appears to be wrong.
>> legend() is a separate function, not a parameter of plot.default
>> afaics.
>>
>> The following works for me:
>>
>> > densren <- 1.25
>> > plot(1:10)
>> > legend (x="center", legend =bquote(.(densren) (ind./km)^2))
>>
>> See ?legend
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming
>> along and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux
>> > > wrote:
>>
>> Dear listers,
>>
>> I am trying to pass an expression inlcuding a variable and a
>> superpscript to a legend. What I want to obtain is e.g. with
>> densren = 1.25
>>
>> 1.25 ind./km^2
>>
>> I have tried many variants of the following:
>>
>> legend=bquote(.(densren) (ind./km)^2)
>>
>> but if not errors, do obtain
>>
>> 1.25 (ind./km^2)
>>
>> hence not what I want (no parenthesis, 2 in superscript...)
>>
>> Any idea about a correct syntax to get what I need ?
>>
>> Best,
>>
>> Patrick
>>
>>
>>         [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org  mailing
>> list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Bert Gunter
The legend must be "an expression vector."
c("Sans renard",bquote(.(densren) (ind./km)^2))   is not because the first
element is a character string.

This works:

   plot(1:100,1:100,type="n")
   legend(list(x=0,y=100),legend=c(expression("Sans
renard"),bquote(.(densren)
(ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 20, 2019 at 9:02 AM Patrick Giraudoux <
patrick.giraud...@univ-fcomte.fr> wrote:

> Thanks Bert and Peter,
>
> Yes Bert, I was aware of the legend() function syntax, and just quoting
> the legend argument within the function.
>
> However, Bert and Peter, I do not understand why it works with your
> absolutely reproducible examples and not in the slightly (not so slightly
> apparently) different context where I used it...
>
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren)
> (ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")
>
> densren=1.25
> plot(1:100,1:100,type="n")
> legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) * "
> ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"
>
> Probably because the result of bquote() is concatenated in a character
> vector, but how to deal with this ?
>
> Best,
>
> Patrick
>
>
>
> Le 20/10/2019 à 16:42, Bert Gunter a écrit :
>
> Assuming you are using base graphics, your syntax for adding the legend
> appears to be wrong.
> legend() is a separate function, not a parameter of plot.default afaics.
>
> The following works for me:
>
> > densren <- 1.25
> > plot(1:10)
> > legend (x="center", legend =bquote(.(densren) (ind./km)^2))
>
> See ?legend
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux <
> patrick.giraud...@univ-fcomte.fr> wrote:
>
>> Dear listers,
>>
>> I am trying to pass an expression inlcuding a variable and a
>> superpscript to a legend. What I want to obtain is e.g. with densren =
>> 1.25
>>
>> 1.25 ind./km^2
>>
>> I have tried many variants of the following:
>>
>> legend=bquote(.(densren) (ind./km)^2)
>>
>> but if not errors, do obtain
>>
>> 1.25 (ind./km^2)
>>
>> hence not what I want (no parenthesis, 2 in superscript...)
>>
>> Any idea about a correct syntax to get what I need ?
>>
>> Best,
>>
>> Patrick
>>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux
Thanks Bert and Peter,

Yes Bert, I was aware of the legend() function syntax, and just quoting 
the legend argument within the function.

However, Bert and Peter, I do not understand why it works with your 
absolutely reproducible examples and not in the slightly (not so 
slightly apparently) different context where I used it...

densren=1.25
plot(1:100,1:100,type="n")
legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) 
(ind./km)^2)),lty=c(1,2),col=c("black","red"),bty="n")

densren=1.25
plot(1:100,1:100,type="n")
legend(list(x=0,y=100),legend=c("Sans renard",bquote(.(densren) * " 
ind."/"km"^2)),lty=c(1,2),col=c("black","red"),bty="n"

Probably because the result of bquote() is concatenated in a character 
vector, but how to deal with this ?

Best,

Patrick



Le 20/10/2019 à 16:42, Bert Gunter a écrit :
> Assuming you are using base graphics, your syntax for adding the 
> legend appears to be wrong.
> legend() is a separate function, not a parameter of plot.default afaics.
>
> The following works for me:
>
> > densren <- 1.25
> > plot(1:10)
> > legend (x="center", legend =bquote(.(densren) (ind./km)^2))
>
> See ?legend
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux 
>  > wrote:
>
> Dear listers,
>
> I am trying to pass an expression inlcuding a variable and a
> superpscript to a legend. What I want to obtain is e.g. with
> densren = 1.25
>
> 1.25 ind./km^2
>
> I have tried many variants of the following:
>
> legend=bquote(.(densren) (ind./km)^2)
>
> but if not errors, do obtain
>
> 1.25 (ind./km^2)
>
> hence not what I want (no parenthesis, 2 in superscript...)
>
> Any idea about a correct syntax to get what I need ?
>
> Best,
>
> Patrick
>
>
>         [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org  mailing list --
> To UNSUBSCRIBE and more, see
> 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.
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Bert Gunter
Assuming you are using base graphics, your syntax for adding the legend
appears to be wrong.
legend() is a separate function, not a parameter of plot.default afaics.

The following works for me:

> densren <- 1.25
> plot(1:10)
> legend (x="center", legend =bquote(.(densren) (ind./km)^2))

See ?legend

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 20, 2019 at 5:30 AM Patrick Giraudoux <
patrick.giraud...@univ-fcomte.fr> wrote:

> Dear listers,
>
> I am trying to pass an expression inlcuding a variable and a
> superpscript to a legend. What I want to obtain is e.g. with densren = 1.25
>
> 1.25 ind./km^2
>
> I have tried many variants of the following:
>
> legend=bquote(.(densren) (ind./km)^2)
>
> but if not errors, do obtain
>
> 1.25 (ind./km^2)
>
> hence not what I want (no parenthesis, 2 in superscript...)
>
> Any idea about a correct syntax to get what I need ?
>
> Best,
>
> Patrick
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux
Thanks Eric. I got it too already (and already tried some variations 
based on it), but to my understanding it does not include a variable 
whose contents is used in the expression as in the case submitted...


Le 20/10/2019 à 14:56, Eric Berger a écrit :
> I did a Google search on
>
> R plot superscript in legend
>
> and the first search result was
> https://stackoverflow.com/questions/20453408/superscript-r-squared-for-legend 
>
>  which looks like it might address your question.
>
> On Sun, Oct 20, 2019 at 3:30 PM Patrick Giraudoux 
>  > wrote:
>
> Dear listers,
>
> I am trying to pass an expression inlcuding a variable and a
> superpscript to a legend. What I want to obtain is e.g. with
> densren = 1.25
>
> 1.25 ind./km^2
>
> I have tried many variants of the following:
>
> legend=bquote(.(densren) (ind./km)^2)
>
> but if not errors, do obtain
>
> 1.25 (ind./km^2)
>
> hence not what I want (no parenthesis, 2 in superscript...)
>
> Any idea about a correct syntax to get what I need ?
>
> Best,
>
> Patrick
>
>
>         [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org  mailing list --
> To UNSUBSCRIBE and more, see
> 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.
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Eric Berger
I did a Google search on

R plot superscript in legend

and the first search result was
https://stackoverflow.com/questions/20453408/superscript-r-squared-for-legend

 which looks like it might address your question.

On Sun, Oct 20, 2019 at 3:30 PM Patrick Giraudoux <
patrick.giraud...@univ-fcomte.fr> wrote:

> Dear listers,
>
> I am trying to pass an expression inlcuding a variable and a
> superpscript to a legend. What I want to obtain is e.g. with densren = 1.25
>
> 1.25 ind./km^2
>
> I have tried many variants of the following:
>
> legend=bquote(.(densren) (ind./km)^2)
>
> but if not errors, do obtain
>
> 1.25 (ind./km^2)
>
> hence not what I want (no parenthesis, 2 in superscript...)
>
> Any idea about a correct syntax to get what I need ?
>
> Best,
>
> Patrick
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] using a variable and a superscript in a legend

2019-10-20 Thread Patrick Giraudoux
Dear listers,

I am trying to pass an expression inlcuding a variable and a 
superpscript to a legend. What I want to obtain is e.g. with densren = 1.25

1.25 ind./km^2

I have tried many variants of the following:

legend=bquote(.(densren) (ind./km)^2)

but if not errors, do obtain

1.25 (ind./km^2)

hence not what I want (no parenthesis, 2 in superscript...)

Any idea about a correct syntax to get what I need ?

Best,

Patrick


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.