[R] plot numeric vs character
MacQueen, Don
macqueen1 at llnl.gov
Thu Mar 17 15:43:57 CET 2016
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"
<r-help-bounces at r-project.org on behalf of 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://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
>
>______________________________________________
>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