[R] plot numeric vs character

MacQueen, Don macqueen1 at llnl.gov
Thu Mar 17 15:43:57 CET 2016


dotplot(num ~ let, data=mydf)

Don MacQueen

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

On 3/17/16, 3:29 AM, "R-help on behalf of Ivan Calandra"
<r-help-bounces at r-project.org on behalf of ivan.calandra at univ-reims.fr>

>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),
>I would like to do that, which throws an error, most likely because x is
>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 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
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list