[R] Plot question
Marc Schwartz
marc_schwartz at comcast.net
Fri Dec 14 15:24:30 CET 2007
On Fri, 2007-12-14 at 08:16 -0500, Alan Barnett wrote:
> I have some data consisting of multiple trials of an experiment with
> different values of an independent variable. If I run
> R> plot(var,result)
> I get a scatterplot of result versus the independent variable var.
> If I run
> R> plot(as.factor(var),result)
> I get a boxplot of the distribution of result for each value of var. In
> this plot, each boxplot is labeled by the corresponding value of var,
> but the absissas are evenly spaced.
> Is it possible to generate a boxplot with the absissas of each boxplot
> equal to the corresponding value of var?
If you want boxplots, you could do something like this:
CV <- rnorm(100)
FV <- sample(c(1, 3, 6), 100, replace = TRUE)
boxplot(CV ~ factor(FV, levels = seq(max(FV))))
This essentially 'fills in' the missing values (levels) of the factor
variable so that they are included in the plot.
HTH,
Marc Schwartz
More information about the R-help
mailing list