rplotsar

Plot multiple lists in one graph using R


I just started using R, so please be lentient...

Currently I am trying to visualize some disk preformance data gathered by SAR on a Linux server. The header of the CSV data looks like this:

timestamp; DEV; tps; rd_sec/s; wr_sec/s; avgrq-sz; avgqu-sz; await, svctm; %util

DEV represents the device name which I use to group the data:

disks <- split(x = dkstbl, f = dsktbl[, "DEV"])

Using RStudio with the manipulate library, I draw the following plot:

manipulate(
  plot(disks[disk][[1]]$tps[time], 
       disks[disk][[1]]$await[time], 
       xlim = c(0,max(disks[disk][[1]]['tps'])), 
       ylim = c(0,max(disks[disk][[1]]['await'])),
       main = paste(disk,disks[disk][[1]]$X00.00.01[time]),
       xlab = 'IOPS',
       ylab = 'AWAIT'
       ), 
  time = slider(1, 1000),
  disk = picker(as.list(names(disks)))
)

That's almost what I want, but still not exactly. What I want should contain the data of all the disks on one plot and probably will look somehow like so:

manipulate(
  plot(disks[*][[1]]$tps[time], 
       disks[*][[1]]$await[time], 
       xlim = c(0,max(disks[*][[1]]['tps'])), 
       ylim = c(0,max(disks[*][[1]]['await'])),
       main = paste(disks[*][[1]]$X00.00.01[time]),
       xlab = 'IOPS',
       ylab = 'AWAIT'
       ), 
  time = slider(1, 1000)
)

... where the asteriks (*) needs to be replaced with something that works in order to plot all disks at once. How do I achieve that?

Thanks and Cheers, Daniel


Solution

  • First of all, I don't see any reason why you split your original data.frame in the first place.

    Second, if I understand correctly you want to see the observations from all disks, for one specific point in time, right?

    So I think the following solves your problem:

    disk <- do.call("rbind", disks)
    manipulate(
      plot(disk$tps[disk$Time==time],
         disk$await[disk$Time==time],
         xlim = c(0,max(disk$tps)),
         ylim = c(0,max(disk$await)),
         main = "All disks",
         xlab = 'IOPS',
         ylab = 'AWAIT'
      ),
      time = picker(as.list(levels(disk$Time)))
    )
    

    One should strive to keep things simple...