r - Adding a proper title to ggplot -


i've been trying morning , still can't find solution after reading related post on stackoverflow

i have following code:

names <- colnames(df[17:length(df)])  counter = 17l  (i in 1:length(names)) {   df.tax <- subset(df, df[,c(counter)] != 0)   counter = counter + 1l   meta <- subset(df.tax, select=c(1:16))   meltmeta <- melt(meta, id=c("collector", "year","week","cities","provinces"))   ppv <- ggplot(meltmeta, aes(title = paste(names[i]), factor(provinces), value))   ppv + geom_boxplot() + geom_boxplot(aes(fill=collector), alpha=i(0.5)) + geom_point(aes(color=collector), size=1) +facet_wrap(~variable, scale="free")   ggsave(file = paste(names[i], sep=".","provinces_vs_climate.pdf"), width=16, height=8) } 

my issue is, can't add proper title ggplot. @ every iteration of loop, generating new dataframe called df.tax subsetting parts of df. melt df , trying generate plot using ggplot.

i managed save each plot different file name (based on names array) every iteration on ggsave, ggplot keep on generating title "paste(names[i])" each plot.

i tried, get(), paste(), labs()...etc, none work

anyone know how can resolve issue?

as mentioned joran, since version 0.9.2 of ggplot2, easiest way set title plot use ggtitle. using ggtitle code this:

for (i in 1:length(names)) {   df.tax <- subset(df, df[,c(counter)] != 0)   counter = counter + 1l   meta <- subset(df.tax, select=c(1:16))   meltmeta <- melt(meta, id=c("collector", "year","week","cities","provinces"))   ppv <- ggplot(meltmeta, aes(factor(provinces), value))   ppv <- ppv + geom_boxplot()    ppv <- ppv + geom_boxplot(aes(fill=collector), alpha=i(0.5))    ppv <- ppv + geom_point(aes(color=collector), size=1)    ppv <- ppv + facet_wrap(~variable, scale="free")   ppv <- ppv + ggtitle(paste(names[i]))   ggsave(file = paste(names[i], sep=".","provinces_vs_climate.pdf"), width=16, height=8) } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -