[R] unexpected plot behavior

Marc Schwartz marc_schwartz at me.com
Sat Apr 21 18:18:07 CEST 2012


On Apr 21, 2012, at 9:49 AM, Martin Renner wrote:

> When plotting a numerical vector against a factor, 'type="n"' seems to have no affect, e.g. 
>> plot (1:10~factor (1:10), type = "n")
> 
> looks just like
>> plot (1:10~factor (1:10))
> 
> Plotting a numerical against itself works as expected: 
>> plot (1:10, type = "n")
> 
> I see the same behavior under debian gnu/linux, Mac OS X, and Win7 (all current versions, see below). Is this a bug? 
> 
> Regards,
> Martin



This has to do with method dispatch. See ?plot.formula, which is the plot method called you pass a formula, as opposed to passing a vector as in your third example. 

In this case, ?plot.factor is called when the 'x' part of the formula (RHS) is a factor. When plot.factor is called, it internally calls ?boxplot and of course, there is no "type = 'n'" for boxplots, hence it is ignored.

Regards,

Marc Schwartz



More information about the R-help mailing list