Use 100's of plot solution for a data.table? w/ grrrck solution

Why can't I just pass a data.table into this function and use it?

pass df as a dt class and carry on?

g <- qplot(x = df[, index], bins = 10) +

I tried lots of referencing methods to pass the column via index



quoting grrrck:
At this point, it's very hard to tell why you're getting the error. If it's possible for you to post example data I may be able to help further. Also, please share the code that you used to run the function.

In the mean time, here's another version of the function that can be applied to built in data sets, like iris

plot_histograms <- function(df, key = "key-value", pair = "pair-value", outdir = getwd()) {
  ncol_df <- ncol(df)
  for (index in seq_len(ncol_df)) {
    # do whatever needs to be done here to produce a plot for a column
    # I'm using qplot() just to make things easy
    g <- qplot(x = df[, index], bins = 10) +
      ggtitle(paste(key, pair, index, sep = " - "))
    outfile <- sprintf("%s_%s_%03d.pdf", key, pair, index)
    ggsave(filename = file.path(outdir, outfile), g)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.