[R] ggplot2 - facet_grid and facet_wrap

David Hajage dhajage.r at gmail.com
Sat Nov 22 20:07:15 CET 2008


Hello R users (and Hadley)

I have another question about ggplot2 :-)

(version 0.8)

`dat` <-
structure(list(D = c("a", "b", "c", "d"), G = c(1.51520888871520,
1.88812208268440, -6.60521862, 0.55968739), E = c(1.38888592256404,
1.39366168665589, 1.22509259382058, 1.36617701059296), I =
c(6.92634958902857,
6.94416045215158, 13.2179488828556, 10.1993799972675), B =
c(7.04367258675502,
7.41361056949868, 16.3459547875, 12.968224445), F = c(1.52045742504008,
1.51361354379038, 1.77077549933584, 1.64580736760918), A =
c(2.33837047498186,
2.33805720845022, 2.20591935275643, 2.26866576271907), J =
c(4.33205802184905,
4.41713317075078, 11.091251405, 7.21690806), H = c(2.35434145263158,
2.35434145263158, 2.00170987368421, 2.26486776842105), C =
c(6.9118223461127,
6.92991088926983, 16.1293054123787, 10.2251608535304)), .Names = c("D",
"G", "E", "I", "B", "F", "A", "J", "H", "C"), row.names = c(NA,
4L), class = "data.frame")

mdat <- melt(dat, id = "D")

qplot(D, value, data = mdat, fill = D, geom = "bar") + facet_grid(~
variable)
qplot(D, value, data = mdat, fill = D, geom = "bar") + facet_wrap(~
variable)


The first plot is good, but I think there is a problem in the second plot :
the barplots are not in the correct order (compare "G" in the first plot and
in the second plot for example).

I join a pdf file showing the two graphs.

Something is wrong in my code ?

Thank you very much.

david
-------------- section suivante --------------
Une pi?ce jointe autre que texte a ?t? nettoy?e...
Nom: example.pdf
Type: application/pdf
Taille: 47350 octets
Desc: non disponible
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20081122/0f106d0f/attachment.pdf>


More information about the R-help mailing list