[R] using by to plot
David White
dwhite at ling.ohio-state.edu
Tue Aug 28 17:49:36 CEST 2001
%You are making something easy into something difficult. All you need
%is. . .
You are _so_ right! Thanks for setting me straight on how to use plot
sensibly.
S. David White
sdavidwhite at bigfoot.com
Columbus, Ohio
On 28 Aug 2001, Douglas Bates wrote:
%David White <dwhite at ling.ohio-state.edu> writes:
%
%> I would like to use by to create a series of plots, but I'm not sure how
%> to design the function.
%>
%> Here's what I've got:
%>
%> 1. A data frame of observations of measured value 2 measured vlaues and a
%> pch code.
%>
%> V1 V2 pchCode
%> .0045 123 1
%> .0034 145 2
%> .0045 123 1
%> .0046 167 3
%> ...
%>
%> So what I want to do is create a single scatterplot of the multiple
%> conditions (specified by pchCode) and use pchCode to specify the plotting
%> character within the plotting function.
%>
%> I'm imagining something like
%>
%> by(df, pchCode, function(x) plot(V1, V2, pch=pchCode))
%>
%> What I don't know how to code is:
%> 1. getting the pch to be defined by the pchCode
%> 2. specifying that par(new=TRUE) within the by command.
%
%You are making something easy into something difficult. All you need
%is
%
%> ttt
% V1 V2 pchCode
%1 0.0045 123 1
%2 0.0034 145 2
%3 0.0045 123 1
%4 0.0046 167 3
%> str(ttt)
%`data.frame': 4 obs. of 3 variables:
% $ V1 : num 0.0045 0.0034 0.0045 0.0046
% $ V2 : num 123 145 123 167
% $ pchCode: num 1 2 1 3
%> plot(V2 ~ V1, data = ttt, pch = pchCode)
%> # if pchCode is a factor, use as.integer(pchCode)
%
%Arguments like pch are vectorized.
%
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list