[R] plot numeric vs character

PIKAL Petr petr.pikal at precheza.cz
Thu Mar 17 12:42:55 CET 2016


Hi

I am not an expert but it probably results from covenience plot.factor method which calls boxplot when used for or factor data.

See

graphics:::plot.factor
graphics:::boxplot.default

I belive that you can do something with ggplot like (untested)

p <-ggplot(mydf, aes(x=let, y=num))
p+geom_point()
p+geom_jitter()

or change plot.factor method, which is beyound my level.

I considered dotchart but it is used for differnt data structure.

Cheers
Petr

> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ivan
> Calandra
> Sent: Thursday, March 17, 2016 12:01 PM
> To: R list
> Cc: Anne CANER
> Subject: Re: [R] plot numeric vs character
>
> Thanks Petr,
>
> You're right, no need for points().
> But is there an even simpler way? I still find it strange that plot()
> does not allow points to be plotted instead of boxplots when x is a
> factor (because boxplots do not always make sense). Is there a good
> reason for that?
>
> Ivan
>
> --
> Ivan Calandra, PhD
> University of Reims Champagne-Ardenne
> GEGENAA - EA 3795
> CREA - 2 esplanade Roland Garros
> 51100 Reims, France
> +33(0)3 26 77 36 89
> ivan.calandra at univ-reims.fr
> --
> https://www.researchgate.net/profile/Ivan_Calandra
> https://publons.com/author/705639/
>
> Le 17/03/2016 11:48, PIKAL Petr a écrit :
> > Hi
> >
> > It would be easier if mydf$let was factor
> >
> > plot(as.numeric(factor(mydf$let)), mydf$num, xaxt="n") axis(1,
> at=1:3,
> > levels(factor(mydf$let)))
> >
> > Cheers
> > Petr
> >
> >
> >> -----Original Message-----
> >> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ivan
> >> Calandra
> >> Sent: Thursday, March 17, 2016 11:30 AM
> >> To: R list
> >> Cc: Anne CANER
> >> Subject: [R] plot numeric vs character
> >>
> >> Dear useRs,
> >>
> >> I would like to plot data points in a simple scatterplot. I don't
> >> have a lot of data per category, so a boxplot does not make sense.
> >>
> >> Here are some sample data:
> >> mydf <- data.frame(let=rep(letters[1:3],each=3), num=rnorm(9),
> >> stringsAsFactors=FALSE)
> >>
> >> I would like to do that, which throws an error, most likely because
> x
> >> is
> >> character:
> >> plot(mydf$let, mydf$num)
> >>
> >> If I convert to factor(), it plots a boxplot with no possibility
> >> (AFAIK) to plot points:
> >> mydf$let <- factor(mydf$let)
> >> plot(mydf$let, mydf$num, type='p')
> >>
> >> I know I can use the function points() in a somewhat convoluted
> manner:
> >> plot(mydf$num, xlim=c(1,3), type='n', xaxt='n') axis(side=1, at=1:3,
> >> labels=levels(mydf$let)) points(as.numeric(mydf$let), mydf$num)
> >>
> >> Isn't there a simple(r) way? Maybe I just missed something
> obvious...
> >>
> >> Thank you in advance for your help,
> >> Ivan
> >>
> >> --
> >> Ivan Calandra, PhD
> >> University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2
> >> esplanade Roland Garros 51100 Reims, France
> >> +33(0)3 26 77 36 89
> >> ivan.calandra at univ-reims.fr
> >> --
> >>

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.


More information about the R-help mailing list