r - Looping over variables in ggplot -


i want use ggplot loop on several columns create multiple plots, using placeholder in loop changes behavior of ggplot.

if have this:

t <- data.frame(w = c(1, 2, 3, 4), x = c(23,45,23, 34),  y = c(23,34,54, 23), z = c(23,12,54, 32)) 

this works fine:

ggplot(data=t, aes(w, x)) + geom_line() 

but not:

i <- 'x' ggplot(data=t, aes(w, i)) + geom_line() 

which problem if want loop on x, y , z. help?

you need use aes_string instead of aes, this:

ggplot(data=t, aes_string(x = "w", y = i)) + geom_line()  

note w needs specified string, too.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -