Faceting Multiple Plots

190 views
Skip to first unread message

Lighton Phiri

unread,
Dec 19, 2012, 12:48:46 PM12/19/12
to ggplot2
I am working with this dataset[1] and having trouble faceting multiple
plots. How do I go about merging plots on rows 1 and 2 [2] and
faceting by top strip? Each of the column plots share a similar scale
and I want to have them on one plot.

What I have managed to come up with is generated by the code below.

library(ggplot2)
library(reshape2)

dataset <- read.table("dataset.dat", header=TRUE, sep=",", row.names=NULL)
info <- melt(dataset, id.vars=c(1:2))

ggplot(data=info, aes(x=as.factor(W), y=value, group=variable,
shape=variable)) + geom_line() + facet_grid(S ~ variable,
scales="free_y") + scale_y_log10() + theme(axis.text.x =
element_text(angle=90, vjust=0.5))

[1] See attachment (dataset.dat)
[2] See attachment (dataset.png)

Lighton Phiri
http://lightonphiri.org
dataset.dat
dataset.png

Roman Luštrik

unread,
Dec 19, 2012, 12:53:35 PM12/19/12
to Lighton Phiri, ggplot2
What if you use `facet_grid(~ S, scales = "free_y")`? In that case, I would not use `group = variable`, but `colour = variable`.

Cheers,
Roman




Lighton Phiri
http://lightonphiri.org

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
In God we trust, all others bring data.

Lighton Phiri

unread,
Dec 19, 2012, 1:03:51 PM12/19/12
to Roman Luštrik, ggplot2
It doesn't result in desired output, and I get the following 'warning' messages.

geom_path: Each group consist of only one observation. Do you need to
adjust the group aesthetic?
geom_path: Each group consist of only one observation. Do you need to
adjust the group aesthetic?
Lighton Phiri
http://lightonphiri.org

Lighton Phiri

unread,
Dec 19, 2012, 1:09:09 PM12/19/12
to Roman Luštrik, ggplot2
That's it! Thank you very much... I sent through my last email before
I saw your second response. The code below seems to have done the
trick...

ggplot(data=info, aes(x=as.factor(W), y=value, colour=S, group=S,
ncol=1)) + geom_line() + facet_wrap(~ variable, scales="free_y") +
theme(axis.text.x = element_text(angle=90, vjust=0.5)) +
scale_y_log10()

Lighton Phiri
http://lightonphiri.org
Reply all
Reply to author
Forward
0 new messages