On Mon, Jun 15, 2009 at 04:40:49PM +0800, Mao Jianfeng wrote:
> Hi everybody,
>
> I am new to R and programming.
>
> I have a large dataframe composed of two grouping variables (species,
> population, with populations nested in species) and tens of continuously
> numeric variables. For each numeric variable, I want to make a boxplot with
> population as the X axis and the boxes filled according to which species it
> is belonging to. But, that is a definitely tedious work. I followed the
> tutorials in the ggplot2 website. But, I have not found any way to ease this
> work.
I think there must be an easier way, but this one works also:
d = read.table("/tmp/da", header=T)
plotit = function(d, name){
p <- ggplot(d) + geom_boxplot(aes(x=population, fill=species, y=value)) + scale_y_continuous(name)
print(p)
}
pdf("/tmp/1.pdf")
for (i in 3:8){
data = d[,c(1,2,i)]
names(data) = c("species", "population", "value")
plotit(data, names(d)[i])
}
dev.off()
regards,
stefan