Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot data grouped by a factor, but not as a boxplot

Tags:

plot

r

In R, given a vector

casp6 <- c(0.9478638, 0.7477657, 0.9742675, 0.9008372, 0.4873001, 0.5097587, 0.6476510, 0.4552577, 0.5578296, 0.5728478, 0.1927945, 0.2624068, 0.2732615)

and a factor:

trans.factor <- factor (rep (c("t0", "t12", "t24", "t72"), c(4,3,3,3)))

I want to create a plot where the data points are grouped as defined by the factor. So the categories should be on the x-axis, values in the same category should have the same x coordinate.

Simply doing plot(trans.factor, casp6) does almost what I want, it produces a boxplot, but I want to see the individual data points.

like image 805
amarillion Avatar asked Apr 02 '10 17:04

amarillion


1 Answers

10 year old question...but if you want a neat base R solution:

plot(trans.factor, casp6, border=NA, outline=FALSE)
points(trans.factor, casp6)

The first line sets up the plot but draws nothing. The second adds the points. This is slightly neater than the solutions that force x to be numeric.

like image 56
George Savva Avatar answered Sep 22 '22 09:09

George Savva