[R] plot numeric vs character

Ivan Calandra ivan.calandra at univ-reims.fr
Thu Mar 17 11:29:52 CET 2016

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
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calandra at univ-reims.fr

More information about the R-help mailing list