麻烦ggplot中的图层(geom =" line")

时间:2014-12-15 01:39:31

标签: r plot ggplot2

我想在ggplot2中绘制折线图。以下是我的数据的样子

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

以下是我存储在文件recprec.r

中的ggplot代码
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)

执行代码会产生以下错误,并且下图中描绘的字符不显示值之间的行

> source("recprec.r")
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?

enter image description here

我错过了什么?

1 个答案:

答案 0 :(得分:1)

由于您要沿着x轴绘制分类变量(因子),但想要跨类别进行连接,请尝试明确设置group=美学。

ggplot(data=sem1, aes(x=trace, y=precision, group=query)) + 
    geom_line() + geom_text(aes(y=precision + .4, label=precision))