r - ggplot aes eval(parse(text)) -
my data dt has following structure:
structure(list(ticker = c("msdlwi index", "msdlwi index", "msdlwi index", "msdlwi index","msdlwi index", "msdlwi index", "ndleacwf index", "ndleacwf index", "ndleacwf index","ndleacwf index", "ndleacwf index", "ndleacwf index"), date = structure(c(-1l, 89l, 180l, 272l, 364l, 454l, 15705l, 15793l, 15884l, 15978l, 16070l, 16136l), class = c("idate", "date")), value = c(na, -0.02925, -0.180118465104301, 0.124488001005151, 0.0497217814923236,0.0966385660152425, 0.0323951658690891, 0.0842289682913797, 0.00992717655157427, 0.0631103139013451, 0.0782204344979787, 0.00855027196875335)), .names =c("ticker", "date", "value"), row.names = c(na, -12l),class=c("data.table","data.frame")) head(dt,3)
ticker date value 1: msdlwi index 1969-12-31 na 2: msdlwi index 1970-03-31 -0.0292500 3: msdlwi index 1970-06-30 -0.1801185 however, column names can volatile, attempted parameterise them in ggplot call:
var.col="ticker" ggplot(dt, aes(x=date, y=value, colour=eval(parse(text=var.col)))) + geom_line() http://i.stack.imgur.com/h3tbn.png
in plot legend, how display ticker instead of eval(parse(text=var.col))?
there no reason funky eval(parse()) business:
ggplot(dt, aes_string(x="date", y="value", colour=var.col)) + geom_line()
Comments
Post a Comment