R脚本if(nrow(layer_data)== 0)return()参数的长度为零

时间:2013-11-26 16:51:20

标签: r ggplot2 ns-3

我需要绘制我的图形但是我发现了这个错误:if(nrow(layer_data)== 0)return()参数的长度为零。 这是我正在使用的脚本:

library (ggplot2)
library (scales)
library (doBy)

#########################
# Rate trace processing #
#########################
data = read.table ("rate-trace.txt", header=TRUE)
data$Node = factor (data$Node)
data$FaceId <- factor(data$FaceId)
data$Kilobits <- data$Kilobytes * 8
data$Type = factor (data$Type)

# exlude irrelevant types
data = subset (data, Type %in% c("InInterests", "OutInterests", "InData", "OutData"))

# combine stats from all faces
data.combined = summaryBy (. ~ Time + Node + Type, data=data, FUN=sum)

data.root = subset (data.combined, Node == "root")
data.leaves = subset (data.combined, Node %in% c("attacker", "hijacker", "producer", "consumer"))

# graph rates on all nodes in Kilobits
g.all <- ggplot (data.combined) +
  geom_point (aes (x=Time, y=Kilobits.sum, color=Type), size=1) +
  ylab ("Rate [Kbits/s]") +
  facet_wrap (~ Node)

print (g.all)

# graph rates on the root nodes in Packets
g.root <- ggplot (data.root) +
 geom_point (aes (x=Time, y=Kilobits.sum, color=Type),size=2) +
 geom_line (aes (x=Time, y=Kilobits.sum, color=Type), size=0.5) +
 ylab ("Rate [Kbits/s]")

print (g.root)

png ("root-rates.png", width=500, height=250)
print (g.root)
dev.off ()

这是rate-trace.txt的一小部分

Time    Node    FaceId  FaceDescr   Type    Packets Kilobytes   PacketRaw   KilobytesRaw
0.5 consumer    0   dev[0]=net(0,0-4)   InInterests 0   0   0   0
0.5 consumer    0   dev[0]=net(0,0-4)   OutInterests    161.6   5.67969 101 3.5498
0.5 consumer    0   dev[0]=net(0,0-4)   DropInterests   0   0   0   0
0.5 consumer    0   dev[0]=net(0,0-4)   InNacks 0   0   0   0
0.5 consumer    0   dev[0]=net(0,0-4)   OutNacks    0   0   0   0
0.5 consumer    0   dev[0]=net(0,0-4)   DropNacks   0   0   0   0

你有什么想法吗?

0 个答案:

没有答案