[R] Plot of a subset of a data.frame()
Steffen Uhlig
steffen.uhlig at htw-saarland.de
Mon Jul 26 13:38:44 CEST 2010
Hello,
my data.frame is sort of a collection of process values, i.e. huge
run-chart. It consists of a time-stamp in the first column (date as
string), factors in the following columns (used for subset-filtering),
and some process-data columns.
Hereafter, two examples are listed, showing the problems that occour
during print:
At first the example, that works fine:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a = c(1:10) # create a vector of integers
b = rep(c("a","b"),5) # create a vector of chars, used
# as factor-levels
d = rnorm(10) # some random numbers
e = data.frame(a,b,d) # connect to a data.frame
e.1 = subset(e, b=="a") # create two subsets
e.2 = subset(e, b=="b")
plot(d~a, e.1, pch=3, col=2) # plot first data-subset
points(d~a, e.2, pch=4, col=3) # plot the 2nd one
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
all looks fine in theses plots.
However, changing the content of vector "a" to a set of strings the
following happens:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a = c("a","b","c","d","e","f","g","h","i","j")
e = data.frame(a,b,d) # re-build data.frame
e.1 = subset(e, b=="a") # create two subsets
e.2 = subset(e, b=="b")
plot(d~a, e.1, pch=3, col=2)
points(d~a, e.2, pch=4, col=3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plot-command produces horizontal lines instead of dots. This seems
to happen when the x-axis contains strings rather than numbers. is there
a way out?
Best regards,
/Steffen
--
Steffen Uhlig, PhD
Mechatronik und Sensortechnik
HTW des Saarlandes
Goebenstraße 40
66117 Saarbrücken
Tel.: +49 (0) 681 58 67 274
More information about the R-help
mailing list