[R] plot numeric vs character

Ivan Calandra ivan.calandra at univ-reims.fr
Fri Mar 18 09:46:36 CET 2016


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
ivan.calandra at univ-reims.fr
--
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
> <ivan.calandra at univ-reims.fr> 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
>> ivan.calandra at univ-reims.fr
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> ______________________________________________
>> R-help at 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.



More information about the R-help mailing list