Reputation: 12363
I would like to plot a line chart in ggplot2. Here is how my data look like
query,trace,precision,recall
safe.order.q3.txt,rstr_oper_50000_100m,49.8406,24.9156
safe.order.q3.txt,sstr_cpu_50000_100m,49.774,24.8442
safe.order.q3.txt,sstr_oper_50000_100m,49.8735,24.885
safe.sem.q1.txt,ran_50000_100m,74.9204,24.8125
safe.sem.q1.txt,sys_50000_100m,58.1995,11.8975
safe.sem.q1.txt,rstr_cpu_50000_100m,75.6115,25.1855
safe.sem.q1.txt,rstr_oper_50000_100m,75.2262,24.9382
safe.sem.q1.txt,sstr_cpu_50000_100m,74.997,25.0963
safe.sem.q1.txt,sstr_oper_50000_100m,75.4195,25.3233
safe.sem.q2.txt,ran_50000_100m,78.6449,24.6323
safe.sem.q2.txt,sys_50000_100m,10.9353,0.255188
safe.sem.q2.txt,rstr_cpu_50000_100m,79.3762,24.6961
And here is the ggplot code that I store in the file recprec.r
w <- read.csv(file="../queryResults/comparison.100m.dat", head=TRUE, sep=",")
sem1 <- subset(w, query=="safe.sem.q1.txt")
p1 <- ggplot(data=sem1, aes(x=trace, y=precision)) + layer(geom="line") + geom_text(aes(y=precision + .4, label=precision))
print(p1)
The execution of the code produce the following error and the char depicted in the image below where lines between values are not displayed
> source("recprec.r")
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
What did I missed ?
Upvotes: 0
Views: 307
Reputation: 206232
Since you're plotting a categorical variable (factor) along the x-axis but you want to connect across categories, try explicitly setting a group=
aesthetic.
ggplot(data=sem1, aes(x=trace, y=precision, group=query)) +
geom_line() + geom_text(aes(y=precision + .4, label=precision))
Upvotes: 1