0

I have a data that has following form:

first second data_col1 data_col2 data_col3
lu    NA     <number>  <number>  <number>
lu    NA     <number>  <number>  <number>
lu    NA     <number>  <number>  <number>
lu    NA     <number>  <number>  <number>
lu    mult   <number>  <number>  <number>
lu    mult   <number>  <number>  <number>
lu    mult   <number>  <number>  <number>
lu    mult   <number>  <number>  <number>
mult  NA     <number>  <number>  <number>
mult  NA     <number>  <number>  <number>
mult  NA     <number>  <number>  <number>
mult  NA     <number>  <number>  <number>

And so on.

I want to group this data by first two columns and plot them separately.

I try to do this:

comb <- unique(total.df[c(1,2)])
apply(comb, 1, function(x) {
  d<-total.df[total.df$guess==FALSE &
              total.df$second==x[2] &
              total.df$first==x[1] &
              total.df$tasks=='tasks_const',]
  p = ggplot(d, aes(x=d$platform, y=d$time,
                    group=as.factor(d$sched),
             colour=as.factor(d$sched))) +
      geom_point() + geom_line()
  ggsave(filename=sprintf("/tmp/a_%s_%s.png", x[1], x[2]))
})

My comb looks following:

        first   second
1        mult     <NA>
121        lu     mult
241        lu     <NA>
361      heat     mult
481      heat       lu
601      heat     <NA>
721  cholesky     mult
841  cholesky       lu
961  cholesky     heat
1081 cholesky     <NA>
1201 pipeline     mult
1321 pipeline       lu
1441 pipeline     heat
1561 pipeline cholesky
1681 pipeline     <NA>
1801      gen     mult
1921      gen       lu
2041      gen     heat
2161      gen cholesky
2281      gen pipeline
2401      gen     <NA>

facet_wrap almost solves my task, but I want every picture to be separate to able to see what is actually there. And with facet_wrap each of them is too small.

Code with facet_wrap is following:

ggplot(total.df, aes(x=total.df$platform, y=total.df$time,
       group=as.factor(total.df$sched),
       colour=as.factor(total.df$sched))) +
geom_point() + geom_line() + facet_wrap(first ~ second);
1
  • 1
    You don't need to specify total.df in your call of aes(). The first argument of ggplot specifies the data frame. So aes(x=total.df$platform,... can be simplified to aes(x = platform) for example. Commented Jan 27, 2015 at 21:40

1 Answer 1

2

I would probably suggest plotting each graph on a different page of one pdf file. I could also recommend using data.table, as it makes things look nicer:

library(data.table)
total.dt <- data.table(total.df)
setkey(total.dt, first, second)
comb <- unique(total.dt[, list(first, second)])

pdf("test.pdf")
for(n in 1:nrow(comb)){
  d <- total.dt[comb[n, ]][guess == FALSE & tasks == "tasks_const"] 
  print(ggplot(d, aes(x = platform, y = time,
                      group = as.factor(sched),
                      colour = as.factor(sched))) +
        geom_point() + geom_line() + 
        ggtitle(sprintf("first=%s, second=%s", comb[n, first], comb[n, second])))}
dev.off()     
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.