[R] Why does plot() ignore the data type for axis labels?

Mark Difford mark_difford at yahoo.co.uk
Wed Feb 20 09:26:35 CET 2008


Hi Stiffler,

Duncan Murdoch wrote:
>> The point is that a scatterplot is a graph of real numbers, not of
>> integers.  
>> Use a plot designed for a discrete data type if you don't want things 
>> displayed as their real values ...

To drive home Duncan's point (not that it needs it) ...and to complete the
loop, consider how R treats factors:

> x
[1] 1 2 3
> factor(x)
[1] 1 2 3
Levels: 1 2 3

## And:
> factor(x, labels=c("one", "two", "three"))
[1] one   two   three
Levels: one two three

> unclass(factor(x, labels=c("one", "two", "three")))
[1] 1 2 3
attr(,"levels")
[1] "one"   "two"   "three"

It does, in the end, make perfect sense.

HTH, Mark.



Duncan Murdoch-2 wrote:
> 
> On 19/02/2008 5:40 PM, Stiffler wrote:
>> 
>> 
>> Mark Difford wrote:
>>>>> I was wondering why the plot() command ignores the datatype when
>>>>> displaying axis labels...
>>> plot() doesn't ignore the datatype:
>>> [...]
>>> plot(x,y) calls xy.coords(), which recasts x as: x = as.double(x), which
>>> is fine, since x is (also/primarily) numeric.
>>>
>>> HTH, Mark.
>>>
>>>
>> 
>> Thanks for the explanation Mark.
>> 
>> If integers are being recast as doubles R is ignoring/overriding the
>> user's
>> choice of data-type. There may be good reasons for doing that internally
>> (uniformity, code re-use etc) , but it is not what I'd expect as an
>> end-user
>> --- neither ?plot nor ?xy.coords seem to mention that coordinates need to
>> be
>> floating point numbers.
> 
> They don't need to be floating point numbers, they are converted if not.
> 
> The point is that a scatterplot is a graph of real numbers, not of 
> integers.  Use a plot designed for a discrete data type if you don't 
> want things displayed as their real values (see for example barplot, 
> stripchart, dotchart, etc.)
> 
> Duncan Murdoch
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Why-does-plot%28%29-ignore-the-data-type-for-axis-labels--tp15562325p15584404.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list