[R] Plot of a subset of a data.frame()
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Mon Jul 26 14:10:53 CEST 2010
You could have a look at the ggplot2 package to make such plots. The code for the plots is more readable than with base plots.
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)
library(ggplot2)
ggplot(e, aes(x = a, y = d, colour = b, shape = b)) + geom_point()
a = c("a","b","c","d","e","f","g","h","i","j")
e = data.frame(a,b,d) # re-build data.frame
ggplot(e, aes(x = a, y = d, colour = b, shape = b)) + geom_point()
HTH,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org
> [mailto:r-help-bounces op r-project.org] Namens Steffen Uhlig
> Verzonden: maandag 26 juli 2010 13:39
> Aan: r-help op r-project.org
> Onderwerp: [R] Plot of a subset of a data.frame()
>
> 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
>
> ______________________________________________
> R-help op 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.
>
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
More information about the R-help
mailing list