plot numeric vs character

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

plot numeric vs character

Ivan Calandra-4
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
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

PIKAL Petr
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:[hidden email]] 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
> [hidden email]
> --
> https://www.researchgate.net/profile/Ivan_Calandra
> https://publons.com/author/705639/
>
> ______________________________________________
> [hidden email] 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.

________________________________
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.
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Ivan Calandra-4
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
[hidden email]
--
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:[hidden email]] 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
>> [hidden email]
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> [hidden email] 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.
> ________________________________
> 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

PIKAL Petr
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:[hidden email]] 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
> [hidden email]
> --
> 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:[hidden email]] 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
> >> [hidden email]
> >> --
> >>

________________________________
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.
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

John Kane
In reply to this post by Ivan Calandra-4
Another approach using ggplot2 and shamelessly swiped from
http://www.sthda.com/english/wiki/ggplot2-dot-plot-quick-start-guide-r-software-and-data-visualization.

library(ggplot2)
ggplot(mydf, aes(x=let, y=num)) +
  geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5)




John Kane
Kingston ON Canada


> -----Original Message-----
> From: [hidden email]
> Sent: Thu, 17 Mar 2016 11:29:52 +0100
> To: [hidden email]
> 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
> [hidden email]
> --
> https://www.researchgate.net/profile/Ivan_Calandra
> https://publons.com/author/705639/
>
> ______________________________________________
> [hidden email] 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.

____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Ivan Calandra-4
So it looks like there is no better "base" solution than Petr's code...
Thank you for your input anyway!

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
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 17/03/2016 13:04, John Kane a écrit :

> Another approach using ggplot2 and shamelessly swiped from
> http://www.sthda.com/english/wiki/ggplot2-dot-plot-quick-start-guide-r-software-and-data-visualization.
>
> library(ggplot2)
> ggplot(mydf, aes(x=let, y=num)) +
>    geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5)
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
>> -----Original Message-----
>> From: [hidden email]
>> Sent: Thu, 17 Mar 2016 11:29:52 +0100
>> To: [hidden email]
>> 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
>> [hidden email]
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> [hidden email] 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.
> ____________________________________________________________
> Can't remember your password? Do you need a strong and secure password?
> Use Password manager! It stores your passwords & protects your account.
> Check it out at http://mysecurelogon.com/manager
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Boris Steipe
In reply to this post by PIKAL Petr
This:

plot(match(mydf$let, letters), mydf$num)


:-)



On Mar 17, 2016, at 6:48 AM, PIKAL Petr <[hidden email]> wrote:

> 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:[hidden email]] 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
>> [hidden email]
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> [hidden email] 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.
>
> ________________________________
> 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.
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Boris Steipe
And let me add the generalized solution - if you don't have just single letters in the column:

plot(match(mydf$let, names(table(mydf$let))), mydf$num)


Cheers,
Boris

On Mar 17, 2016, at 8:45 AM, Boris Steipe <[hidden email]> wrote:

> This:
>
> plot(match(mydf$let, letters), mydf$num)
>
>
> :-)
>
>
>
> On Mar 17, 2016, at 6:48 AM, PIKAL Petr <[hidden email]> wrote:
>
>> 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:[hidden email]] 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
>>> [hidden email]
>>> --
>>> https://www.researchgate.net/profile/Ivan_Calandra
>>> https://publons.com/author/705639/
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>> ________________________________
>> 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.
>> ______________________________________________
>> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

MacQueen, Don
In reply to this post by Ivan Calandra-4
Try

require(lattice)
dotplot(num ~ let, data=mydf)



--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 3/17/16, 3:29 AM, "R-help on behalf of Ivan Calandra"
<[hidden email] on behalf of [hidden email]>
wrote:

>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
>[hidden email]
>--
>https://www.researchgate.net/profile/Ivan_Calandra
>https://secure-web.cisco.com/1yNnarZiCKUGYfSH5J2-EbF7-AArb-PmFBicLRM4tZ6aU
>HoIat5tkl5G1tDBWGbmAtfy2rKUMIAZ66QtApYQAaNn3CMmTJjQ1hLMhdkSkvRy5Xybui_V323
>YC17MiU81U_pFgX509cGmkKLXUR0SrR37kW4nS_9dceMbPir9PJL6homj56lCgTPl4i-RnpaGa
>0c3wWDheaJMEnOGkiNM-DTAg-TytL837N8slaOoHk30LoN_nZdOYAbK1afmJdDBChYrPhM28hk
>VbVrP99eKJ8rZl3jO1VsBJ_2fO8BICSQnoamvGo1v9uBfNEP0yswoj9p0zeilFKVII8JQ6CFlx
>jKfohfdIaEfstzBYALjaJSo/https%3A%2F%2Fpublons.com%2Fauthor%2F705639%2F
>
>______________________________________________
>[hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Duncan Mackay-4
In reply to this post by Ivan Calandra-4
I haven't been following the thread but!
If you want to use lattice xyplot

# create x values in their right position --
# assuming equal spacing
mydf$x = rep(1:3, each = 3)

library(lattice)
xyplot(num ~ x, mydf,
             scales = list(x = list(at = 1:3, label = letters[1:3])),
             xlab = "")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: [hidden email]



-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Ivan
Calandra
Sent: Thursday, 17 March 2016 23:26
To: R list
Cc: Anne CANER
Subject: Re: [R] plot numeric vs character

So it looks like there is no better "base" solution than Petr's code...
Thank you for your input anyway!

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
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 17/03/2016 13:04, John Kane a écrit :
> Another approach using ggplot2 and shamelessly swiped from
>
http://www.sthda.com/english/wiki/ggplot2-dot-plot-quick-start-guide-r-softw
are-and-data-visualization.

>
> library(ggplot2)
> ggplot(mydf, aes(x=let, y=num)) +
>    geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5)
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
>> -----Original Message-----
>> From: [hidden email]
>> Sent: Thu, 17 Mar 2016 11:29:52 +0100
>> To: [hidden email]
>> 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
>> [hidden email]
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> [hidden email] 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.
> ____________________________________________________________
> Can't remember your password? Do you need a strong and secure password?
> Use Password manager! It stores your passwords & protects your account.
> Check it out at http://mysecurelogon.com/manager
>
>
>

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: plot numeric vs character

Ivan Calandra-4
In reply to this post by Ivan Calandra-4
That does the trick with base functions!
Thanks Dennis.

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
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 17/03/2016 20:48, Dennis Murphy a écrit :

> Hi:
>
> Try
>
> mydf <- data.frame(let=rep(letters[1:3],each=3), num=rnorm(9),
>                     stringsAsFactors=FALSE)
>
> stripchart(num ~ let, data = mydf, pch = 19, vertical = TRUE)
>
>
> Dennis
>
> On Thu, Mar 17, 2016 at 3:29 AM, Ivan Calandra
> <[hidden email]> wrote:
>> 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
>> [hidden email]
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.