[R-br] [Dúvida] Combinar expression e paste.

Benilton Carvalho beniltoncarvalho em gmail.com
Terça Maio 21 23:46:03 BRT 2013


na real, vc vai querer procurar como fazer uma tabela no canto
superior direito (acho q o demo(plotmath)  serve de exemplo)...

uma solucao relativamente simples (mas q vc pode nao achar "legal"
esteticamente) e' fazer "zero padding"...

black2=black3=c(10.03,1,2)
red2=red3 =c(1.3,100.1,2)
blue3 =blue2=c(1,10.02,2)
orange3=orange2=c(4,4,10.1)

makeExp <- function(L, a, b)
    eval(substitute(expression(paste(lambda==L," , ", "a"==a, ", b"==b)),
                    list(L=sprintf('%06.2f', L),
                         a=sprintf('%06.2f', a),
                         b=sprintf('%06.2f', b))))

plot(1)
legend("topright", legend =
       c(makeExp(black3, black2[1], black2[2]),
         makeExp(red3, red2[1], red2[2]),
         makeExp(blue3, blue2[1], blue2[2]),
         makeExp(orange3, orange2[1], orange2[2])),
       bty="n", lty=c(1,1,1,1), lwd=c(2,2,2,2),
       col=c("black", "red", "darkblue", "orange"))

Em 21 de maio de 2013 23:21, Pedro Rafael
<pedro.rafael.marinho em gmail.com> escreveu:
> Com essa gambiarra acho que roda.
>
> rm(list=ls(all=TRUE))
> black2 = black3=c(10.03,1,2)
> red2 = red3 =c(1.3,100.1,2)
> blue3 =blue2 = c(1,10.02,2)
> orange3 = orange2 = c(4,4,10.1)
>
>
> plot(1)
> legend("topright", legend =
>
>          c(eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
> b"==b)), list(L = black3, a = black2[1], b=black2[2]))),
>
>            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
> b"==b)), list(L = red3, a = red2[1], b=red2[2]))),
>
>            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
> b"==b)), list(L = blue3, a = blue2[1], b=blue2[2]))),
>
>            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
> b"==b)), list(L = orange3, a = orange2[1], b=orange2[2])))),
>        bty="n", lty = c(1,1,1,1), col = c("black", "red", "darkblue",
> "orange"), lwd=c(2,2,2,2))
>
>
>
> [   ],
> Pedro Rafael Diniz Marinho.
>
>
> Em 21 de maio de 2013 23:16, beniltoncarvalho [via R-br]
> <ml-node+s2285057n4659385h12 em n4.nabble.com> escreveu:
>>
>> exemplo nao reproduzivel... experimente abrir uma sessao nova do R,
>> copiar e colar....
>>
>> Em 21 de maio de 2013 23:10, Pedro Rafael
>> <[hidden email]> escreveu:
>>
>> > Veja esse exemplo:
>> >
>> > black=c(10.03,1,2)
>> > plot(1)
>> >
>> > legend("topright", legend =
>> >
>> >          c(eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
>> > b"==b)), list(L = black3, a = black2[1], b=black2[2]))),
>> >
>> >            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
>> > b"==b)), list(L = red3, a = red2[1], b=red2[2]))),
>> >
>> >            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
>> > b"==b)), list(L = blue3, a = blue2[1], b=blue2[2]))),
>> >
>> >            eval(substitute(expression(paste(lambda==L," , ", "a"==a, ",
>> > b"==b)), list(L = orange3, a = orange2[1], b=orange2[2])))),
>> >        bty="n", lty = c(1,1,1,1), col = c("black", "red", "darkblue",
>> > "orange"), lwd=c(2,2,2,2))
>> >
>> > Observe que os números tem quantidades de dígitos diferentes, umas
>> > linhas
>> > ficando maiores e outras menores. Não teria como "justificar" essas
>> > legendas? Não sei se fui claro...
>> >
>> > Obrigado pela ajuda.
>> >
>> > [   ],
>> > Pedro Rafael Diniz Marinho.
>> >
>> >
>> > Em 21 de maio de 2013 22:33, beniltoncarvalho [via R-br]
>> > <[hidden email]> escreveu:
>> >>
>> >> "alinhar" com respeito a q?
>> >>
>> >> plot(1)
>> >> ## alinhado no canto inferior direito
>> >> legend('bottomright', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado no canto inferior esquerdo
>> >> legend('bottomleft', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado no canto superior direito
>> >> legend('topright', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado no canto superior esquerdo
>> >> legend('topleft', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado no centro
>> >> legend('center', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado no topo
>> >> legend('top', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado na base
>> >> legend('bottom', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado na direita
>> >> legend('right', legend=substitute(beta==val, list(val=beta1)))
>> >> ## alinhado na esquerda
>> >> legend('left', legend=substitute(beta==val, list(val=beta1)))
>> >>
>> >>
>> >> Em 21 de maio de 2013 22:07, Pedro Rafael
>> >> <[hidden email]> escreveu:
>> >>
>> >> > Existe alguma forma de alinhar a legenda?
>> >> >
>> >> > [   ],
>> >> > Pedro Rafael Diniz Marinho.
>> >> >
>> >> >
>> >> > Em 17 de maio de 2013 01:13, Pedro Rafael <[hidden email]>
>> >> > escreveu:
>> >> >
>> >> >> Muito obrigado a todos. Obrigado André.
>> >> >>
>> >> >> Robert, muito interessante sua solução. Em geral qual a utilidade do
>> >> >> comando substitute? Ele ajuda além dessa situações à resolver que
>> >> >> tipo
>> >> >> de
>> >> >> problemas?
>> >> >>
>> >> >> Obrigado.
>> >> >>
>> >> >> [   ],
>> >> >> Pedro Rafael Diniz Marinho.
>> >> >>
>> >> >>
>> >> >> Em 17 de maio de 2013 00:52, Robert Iquiapaza [via R-br]
>> >> >> <[hidden email]> escreveu:
>> >> >>
>> >> >>> Pode usar
>> >> >>>
>> >> >>> beta1=10
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> legend("topright",eval(substitute(expression(paste(beta==A)),list(A=beta1))))
>> >> >>>
>> >> >>> Sds
>> >> >>>
>> >> >>> From: [hidden email]
>> >> >>> Sent: Friday, May 17, 2013 12:06 AM
>> >> >>> To: [hidden email]
>> >> >>> Subject: Re: [R-br][Dúvida] Combinar expression e paste.
>> >> >>>
>> >> >>> Olá André. O problema é que o beta foi chamado em linha diferente.
>> >> >>> Minha
>> >> >>> dúvida é como jogar o valor da variável beta na primeira linha da
>> >> >>> legenda
>> >> >>> que fique (a = 10). O beta que você chamou estava fora do
>> >> >>> expression.
>> >> >>> Ou
>> >> >>> seja, estava em linha diferente do beta =.
>> >> >>>
>> >> >>> Gostaria de uma legenda do tipo:
>> >> >>>
>> >> >>> beta = 10.
>> >> >>>
>> >> >>> [   ],
>> >> >>> Pedro Rafael Diniz Marinho.
>> >> >>>
>> >> >>>
>> >> >>> Em 16 de maio de 2013 23:53, andrebvs [via R-br] <[hidden email]>
>> >> >>> escreveu:
>> >> >>>
>> >> >>>>
>> >> >>>> Olá Pedro, acho que é isso,
>> >> >>>>
>> >> >>>> beta = 10
>> >> >>>> plot(1:5, 1:5,type="n",main="Expressões
>> >> >>>> Matemáticas",xlab="",ylab="")
>> >> >>>> legend("topright",legend = c(expression(beta, paste("a =
>> >> >>>> ")),beta))
>> >> >>>>
>> >> >>>> Att.
>> >> >>>> André BVS
>> >> >>>>
>> >> >>>> ________________________________
>> >> >>>> Em 16/05/2013 23:36, Pedro Rafael < [hidden email] > escreveu:
>> >> >>>> Pessoal estou fazendo alguns gráficos e estou combinando os
>> >> >>>> comandos
>> >> >>>> expression e paste. O problema é que quando chamo o comando paste
>> >> >>>> dentro do
>> >> >>>> comando expression só estou conseguindo colocar os valores
>> >> >>>> numéricos
>> >> >>>> das
>> >> >>>> variáveis digitando esses valores.
>> >> >>>> Por exemplo:
>> >> >>>>
>> >> >>>> beta = 10
>> >> >>>> legend("topright", legend = c(expression(beta, paste(" a= 10")))
>> >> >>>>
>> >> >>>> Se eu fizer  legend("topright", legend = c(expression(beta,
>> >> >>>> paste(" =
>> >> >>>> ",
>> >> >>>> beta))) o valor 10 da variável beta não é substituído.
>> >> >>>> Gostaria de alguma forma de não precisar digitar uma informação
>> >> >>>> que
>> >> >>>> já
>> >> >>>> tenho em uma variável.
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>> [   ],
>> >> >>>> Pedro Rafael Diniz Marinho.
>> >> >>>>
>> >> >>>>
>> >> >>>> _______________________________________________
>> >> >>>> R-br mailing list
>> >> >>>> [hidden email]
>> >> >>>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> >> >>>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e
>> >> >>>> forneça
>> >> >>>> código mínimo reproduzível.
>> >> >>>>
>> >> >>>> ________________________________
>> >> >>>> If you reply to this email, your message will be added to the
>> >> >>>> discussion
>> >> >>>> below:
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>> http://r-br.2285057.n4.nabble.com/R-br-Duvida-Combinar-expression-e-paste-tp4659328p4659330.html
>> >> >>>> To unsubscribe from R-br, click here.
>> >> >>>> NAML
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> ________________________________
>> >> >>> _______________________________________________
>> >> >>> R-br mailing list
>> >> >>> [hidden email]
>> >> >>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> >> >>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e
>> >> >>> forneça
>> >> >>> código mínimo reproduzível.
>> >> >>>
>> >> >>>
>> >> >>> _______________________________________________
>> >> >>> R-br mailing list
>> >> >>> [hidden email]
>> >> >>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> >> >>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e
>> >> >>> forneça
>> >> >>> código mínimo reproduzível.
>> >> >>>
>> >> >>> ________________________________
>> >> >>> If you reply to this email, your message will be added to the
>> >> >>> discussion
>> >> >>> below:
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> http://r-br.2285057.n4.nabble.com/R-br-Duvida-Combinar-expression-e-paste-tp4659328p4659335.html
>> >> >>> To unsubscribe from R-br, click here.
>> >> >>> NAML
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > R-br mailing list
>> >> > [hidden email]
>> >> > https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> >> > Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> >> > código
>> >> > mínimo reproduzível.
>> >> _______________________________________________
>> >> R-br mailing list
>> >> [hidden email]
>> >> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> >> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> >> código mínimo reproduzível.
>> >>
>> >>
>> >> ________________________________
>> >> If you reply to this email, your message will be added to the
>> >> discussion
>> >> below:
>> >>
>> >>
>> >> http://r-br.2285057.n4.nabble.com/R-br-Duvida-Combinar-expression-e-paste-tp4659328p4659382.html
>> >> To unsubscribe from R-br, click here.
>> >> NAML
>> >
>> >
>> >
>> > _______________________________________________
>> > R-br mailing list
>> > [hidden email]
>> > https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> > Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> > código
>> > mínimo reproduzível.
>> _______________________________________________
>> R-br mailing list
>> [hidden email]
>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> código mínimo reproduzível.
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://r-br.2285057.n4.nabble.com/R-br-Duvida-Combinar-expression-e-paste-tp4659328p4659385.html
>> To unsubscribe from R-br, click here.
>> NAML
>
>
>
> _______________________________________________
> R-br mailing list
> R-br em listas.c3sl.ufpr.br
> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código
> mínimo reproduzível.


Mais detalhes sobre a lista de discussão R-br