0

I need to plot my graph but I found this error: if (nrow(layer_data) == 0) return() argument is of length zero. This is the script that I'm using:

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 ()

And this is a little part of the 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

Do you have any idea?

user2369478
  • 63
  • 11
  • You haven't provided enough information. Where exactly does the error occur? Can you provide a small reproducible example that will allow us to generate the same error? – joran Nov 26 '13 at 17:04
  • Please `dput` a sample of _the relevant data set_, and the plot command that triggers the error. – Henrik Nov 26 '13 at 17:04
  • @joran this is the line that produce the error 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]") I runned this script with: > source("myscript.R") – user2369478 Nov 26 '13 at 19:40
  • Ok, now how do I run your code? The problem will be with the data structures you're passing to `ggplot`, but there's no way for anyone to investigate or inspect them because....we can't run your code without your data. You need to provide a reproducible example. – joran Nov 26 '13 at 19:44
  • @Henrik what do you mean with "dput a sample"? I really don't have experience with R programming, sorry. – user2369478 Nov 26 '13 at 19:46
  • @Joran I think that if you try with my code and the input file that I've posted should be "work" – user2369478 Nov 26 '13 at 19:47
  • Nonsense. You provided only a tiny subset of your data. Your code explicitly knocks your data down only to `Node == "Root"`, which doesn't occur in your example data. So _obviously_ it won't work with your example data. – joran Nov 26 '13 at 19:49
  • @user2369478, Sorry, I should have been more clear. Please have a look at [**this post on how to easily create a minimal, reproducible example**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610), e.g. by using `dput`. It will make it very much easier to help you, which in turn will make people much more likely to help. Otherwise your question will soon drown among the loads of question pouring in to SO every day. ;) Again, post _only_ the relevant part of the data that actually is used in your plot commands. – Henrik Nov 26 '13 at 19:49
  • You can close the topic. There was an error in the file in input, where I named 'root' as 'router'. Thanks to everyone. – user2369478 Nov 26 '13 at 21:38

0 Answers0