[R] Stacked barplot of timeseries data
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Jun 4 02:18:23 CEST 2008
Here is a variation of the example below which uses
your data. Paste this into an R session:
Lines <- "19:08:15 %usr %nice %sys %idle
19:08:16 5 0 10 86
19:08:17 17 0 14 69
19:08:18 5 0 8 87
19:08:19 10 0 10 81
19:08:20 3 0 7 90
19:08:21 4 0 8 88
"
library(zoo)
library(chron)
# in reality the commented line next replaces the one after it
# z <- read.csv("myfile.dat", header = TRUE, FUN = times)
z <- read.zoo(textConnection(Lines), header = TRUE, FUN = times)
colnames(z) <- sub("X.", "% ", colnames(z))
barplot(z[, 1:3], legend = TRUE, col = 1:3)
On Tue, Jun 3, 2008 at 7:47 PM, Achim Zeileis
<Achim.Zeileis at wu-wien.ac.at> wrote:
> On Tue, 3 Jun 2008, Demetri S. Mouratis wrote:
>
>> Hi,
>>
>> I'm trying to plot time-series data where each sample breaks down the
>> percentage of CPU time spent in each of four states (usr, nice, sys, idle)
>>
>>
>> 19:08:15 %usr %nice %sys %idle
>> 19:08:16 5 0 10 86
>> 19:08:17 17 0 14 69
>> 19:08:18 5 0 8 87
>> 19:08:19 10 0 10 81
>> 19:08:20 3 0 7 90
>> 19:08:21 4 0 8 88
>> [on and on for many samples]
>>
>> The plot I'm aiming for would stack the first three states in a colored
>> barplot, so you get a visual sense of how busy the system is over the course
>> of the day, and which state the CPU is spending its time in. (I've done
>> this as area charts as well).
>>
>> barplot() looked promising, but it wants to stack the columns instead of
>> the rows.
>>
>> Anybody have a good solution for this?
>
> The "zoo" package provides a barplot() method for "zoo" series.
>
> Example with some artificial data:
>
> library("zoo")
> x <- matrix(runif(44), ncol = 4)
> colnames(x) <- c("%usr", "%nice", "%sys", "%idle")
> z <- zoo(x, Sys.time() - c(10:0))
> barplot(z, legend = TRUE)
>
> hth,
> Z
>
>> Thanks!
>> ...Demetri
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list