[R] ERROR need finite 'ylim' values

Giuseppe gbarbesino at gmail.com
Sun Jun 13 22:59:55 CEST 2010



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.
> 
> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
> 
> 
Thank you Peter, both your solutions worked for me. Why do you insist for
using data = argument?
Giuseppe
Giuseppe
-- 
View this message in context: http://r.789695.n4.nabble.com/ERROR-need-finite-ylim-values-tp2253388p2253767.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list