这个小组非常乐于助人,我非常感谢所有的帮助。你们真棒。我搜索但找不到答案。我有一个数据框,其中包括第一列服务器名称和其他具有不同的指标。我希望能够使用ggplot2来浏览数据框并根据唯一行(服务器名)创建图表。如果有大量数据集,我该怎么做呢?
以下是一个示例数据集:
Hostname Date CPU Mem cpu avg io mem
host1 2012-01-01 01:00:00 27.24 2.33 0.47 2.33 27.20
host1 2012-01-01 02:00:00 28.00 22.38 36.50 22.38 27.49
host2 2012-01-01 03:00:00 29.31 7.58 12.23 7.58 28.56
host2 2012-01-01 04:00:00 29.37 2.44 0.35 2.44 29.30
host3 2012-01-01 05:00:00 29.07 2.86 1.04 2.86 28.02
host3 2012-01-01 06:00:00 28.05 2.74 0.67 2.74 27.96
> str(yy)
List of 10
$ Hostname : Factor w/ 37 levels "host1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Date : POSIXct[1:26088], format: "2012-01-01 01:00:00" "2012-01-01
02:00:00" "2012-01-01 03:00:00" "2012-01-01 04:00:00" ...
$ variable : chr [1:26088] "1:00:00" "2:00:00" "3:00:00" "4:00:00" ...
$ 5 : num [1:26088] 27.2 28 29.3 29.4 29.1 ...
$ 60 : num [1:26088] NA NA NA NA NA NA NA NA NA NA ...
$ 61 : num [1:26088] NA NA NA NA NA NA NA NA NA NA ...
$ CPUAVG : num [1:26088] 2.33 22.38 7.58 2.44 2.86 ...
$ CPUAVG+Sev: num [1:26088] 0.47 36.5 12.23 0.35 1.04 ...
$ CPUMaximum: num [1:26088] 2.33 22.38 7.58 2.44 2.86 ...
$ MemoryAVG : num [1:26088] 27.2 27.5 28.6 29.3 28 ...
- attr(*, "row.names")= int [1:26088] 1 2 3 4 5 6 7 8 9 10 ...
- attr(*, "idvars")= chr [1:3] "Hostname" "Date" "variable"
- attr(*, "rdimnames")=List of 2
..$ :'data.frame': 26088 obs. of 3 variables:
.. ..$ Hostname: Factor w/ 37 levels "host1",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ Date : Factor w/ 31 levels "01/01/2012","01/02/2012",..: 1 1 1 1 1 1 1 1
1 1 ...
.. ..$ variable: Factor w/ 24 levels "Hour1","Hour2",..: 1 2 3 4 5 6 7 8 9 10 ...
..$ :'data.frame': 7 obs. of 1 variable:
.. ..$ MetricType: Factor w/ 7 levels "5","60","61",..: 1 2 3 4 5 6 7
答案 0 :(得分:1)
对我而言,这听起来像个问题。这是一个例子。更新了您的数据
# Dummy data
x <- data.frame(
hostname=rep(paste("host",1:3,sep=""),1000),
date=as.Date(1:1000,origin="2005-01-01"),
CPUMEM=rnorm(1000)+20,
CPU=rnorm(1000)+10,
avg=rnorm(1000)+10,
io=rnorm(1000)+5,
mem=rnorm(1000)+27)
x <- melt(x, c("hostname","date"))
ggplot(x, aes(date,value, color=variable)) + geom_line() + facet_grid(~hostname)