[R] ERROR need finite 'ylim' values
David Winsemius
dwinsemius at comcast.net
Sun Jun 13 22:55:54 CEST 2010
On Jun 13, 2010, at 3:49 PM, Peter Ehlers wrote:
> Giuseppe,
>
> See comments below.
>
> On 2010-06-13 10:24, David Winsemius wrote:
>>
>>
>> Giuseppe wrote:
>>>
>>> Hello:
>>> I use R with MAC
>>> I have a simple data table, numeric and text columns, named dt.
>>> The table
>>> is imported through read.csv from a csv file. Row numbers are
>>> automatically assigned, header is set to TRUE. there are 599 rows
>>> and
>>> several columns.
>>>
>>> I am trying to plot using the stripchart command: one numeric
>>> variable
>>> (say dt$fnatg) vs a text column (say dt$pat). dt$pat contains one
>>> of 3
>>> values: "pos", "neg", ""
>>>
>>> So I issue the following command:
>>>
>>>> stripchart (dt$fnatg~dt$pat)
>>>
>>> and works well. it works well also with several options and nuances:
>>>
>>>> stripchart (dt$fnatg ~ dt$pat, method ="jitter", jitter = 0.3,
>>>> vertical
>> =TRUE,log="y", pch=1, ylab="Thyroglobulin (ng/mL)",xlab="Surgical
>> Pathology")
>>>
>>> Now I want my graph to exclude values for which dt$pat == ""
>>>
>>> I tried:
>>>
>>>> stripchart (dt$fnatg ~ dt$pat, method ="jitter", subset (dt,
>> dt$pat!=""),jitter = 0.3, vertical =TRUE,log="y", pch=1,
>> ylab="Thyroglobulin
>> (ng/mL)",xlab="Surgical Pathology")
>>>
>>> there is no effect: the plot contains the same values as before
>>>
>>> the I tried first subsetting the table:
>>>
>>>> patonly<-(dt, dt$pat!="") which works well in creating a new table
>> excluding the unwanted rows. I have noticed that the new table
>> keeps the
>> same row numbers assigned in the previous table. So row numbers now
>> go 1 to
>> 599 but with some intervals (for example there is no row 475 etc.).
>>>
>>> then I use:
>>>
>>>> stripchart (patonly$fnatg ~ patonly$pat, method ="jitter", jitter
>>>> = 0.3,
>> vertical =TRUE,log="y", pch=1, ylab="Thyroglobulin (ng/
>> mL)",xlab="Surgical
>> Pathology")
>>>
>>> and I get the following error:
>>>
>>> Error in plot.window(...) : need finite 'ylim' values
>>> In addition: Warning messages:
>>> 1: In min(x) : no non-missing arguments to min; returning Inf
>>> 2: In max(x) : no non-missing arguments to max; returning -Inf
>>> 3: In min(x) : no non-missing arguments to min; returning Inf
>>> 4: In max(x) : no non-missing arguments to max; returning -Inf
>>>
>>> I f I try the same command but I use another text variable (for
>>> example
>>> patonly$gr) in the same table to split the plot, it now works:
>>>
>>>> stripchart (patonly$fnatg ~ patonly$gr, method ="jitter", jitter
>>>> = 0.3,
>> vertical =TRUE,log="y", pch=1, ylab="Thyroglobulin (ng/
>> mL)",xlab="Surgical
>> Pathology")
>>>
>>>
>>> My question is two fold:
>>> Why does not the subset command work within the stripchart command?
>>>
>>> Why the subsetted table cannot be used in the stripchart command,
>>> when the
>>> plotting variable is the same previously used in the subsetting
>>> process?
>>>
>>>
>>
>> You appear to have adopted a strategy of using positional matching.
>> Naming
>> your arguments will often result in more informative error messages.
>> Looking at the help page for stripchart, it appears that there is no
>> "subset" parameter to set in any of its methods and only the
>> formula method
>> has a data argument. It should work with:
>>
>> stripchart(formula1 , data=subset(dta,
>> subset=criteria), ....<rest of
>> arguments preferably named> )
>>
>> Your other option might be to use the with() function:
>>
>> with( subset(patonly, pat!=""), stripchart(fnatg ~ gr, ...<named
>> arguments>) )
>>
>>
>> HTH. and if it doesn't, then submit a reproducible data example to
>> work
>> with.
>
> Actually, Giuseppe appears to have stumbled upon a bug in the
> stripchart() function.
I thought when Guisseppe wrote:
>
> I tried:
>
>> stripchart (dt$fnatg ~ dt$pat, method ="jitter", subset (dt,
dt$pat!=""),jitter = 0.3, vertical =TRUE,log="y", pch=1,
ylab="Thyroglobulin
(ng/mL)",xlab="Surgical Pathology")
... that the expression: subset(dt, dt$pat!="") , would get
erroneously matched to "dlab", the third parameter in the formula
method arg list, but maybe it would get matched to the "data", the
second parameter. I would also worry that specifying a data object,
but then in a sense contravening that specification by reference to
the full name in the formula specification (dt$fnatg) might cause
problems.
>
> First, here's a fix:
> After your command
>
> patonly<-(dt, dt$pat!="")
>
> which I assume is meant to be
>
> patonly <- subset(dt, dt$pat!="")
>
> and which can be written as
>
> patonly <- subset(dt, pat!="")
>
> you should issue this:
>
> patonly$pat <- factor(patonly$pat)
>
> which will remove the empty level; stripchart() should
> work well after that (and do use the data= argument
> rather than dt$...).
>
> Alternatively, you could change your "text" variables
> (which I assume are factors) to character values (or
> re-import your data with stringsAsFactors = FALSE).
>
>
> Now for the bug in stripchart():
> If the *first* group of the grouping variable is
> empty, then stripchart() has a problem determining
> the range of data values (x-values for horizontal
> charts, y-values otherwise). I can replicate your
> problem withe OrchardSprays dataset:
>
> # this works:
> stripchart(decrease ~ treatment, data = OrchardSprays,
> subset = treatment != "B")
>
> # this doesn't
> stripchart(decrease ~ treatment, data = OrchardSprays,
> subset = treatment != "A")
>
> I'll be submitting a bug report (and I think the fix
> is easy).
>
> -Peter Ehlers
>
>
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list