首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在同一in图中的多个线条图

在同一in图中的多个线条图
EN

Stack Overflow用户
提问于 2015-06-02 22:18:49
回答 2查看 252关注 0票数 3

我正在根据这些数据创建一个线条图。有人知道如何在同一图表中添加另一行(包含第二组召回和精确点)吗?

代码语言:javascript
复制
recall11Point    = c(0.2, 0.2, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.8, 1.0)
precision11Point = c(1.0, 0.5, 0.67, 0.5, 0.4, 0.5,0.43,0.38,0.44,0.5)
d = data.frame("Recall" = recall11Point, "Precision" = precision11Point);

# old fashioned plotting
#plot(y=precision11Point, x=recall11Point, type="l")

ggplot(data=d, aes(x=Recall, y=Precision)) +
  geom_line(size=2, colour="red") +
  geom_point(size=10)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-02 22:32:00

代码语言:javascript
复制
d = data.frame(  "Recall" = c(0.2, 0.2, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.8, 1.0)
               , "Precision" = c(1.0, 0.5, 0.67, 0.5, 0.4, 0.5,0.43,0.38,0.44,0.5)
               ,  "Recall2" = seq(0,0.9, by = 0.1)
               ,  "Precision2" = seq(0,0.9, by = 0.1)
)

library(ggplot2)

ggplot(data=d) +
  geom_line(aes(x=Recall, y=Precision), size=1, colour="red") +
  geom_point(aes(x=Recall, y=Precision), size=5, color = "red") + 
  geom_line(aes(x=Recall2, y=Precision2), size=1, colour="blue") +
  geom_point(aes(x=Recall2, y=Precision2), size=5, colour="blue") +
  theme_bw() + 
  theme( panel.grid.minor = element_blank(), panel.grid.major = element_blank() ) 

票数 3
EN

Stack Overflow用户

发布于 2015-06-02 22:33:03

您可以像这样创建第二个数据帧dt2

代码语言:javascript
复制
dt2 <- data.frame(Recall=recall11Point+runif(10), Precision=precision11Point+runif(10))
ggplot(data=d, aes(x=Recall, y=Precision)) +
  geom_line(size=2, colour="red") +
      geom_point(size=10)+
          geom_line(data=dt2, size=2, aes(x=Recall, y=Precision), colour="red") +
              geom_point(data=dt2, aes(x=Recall, y=Precision), size=10)

或者,您可以创建单个数据框架并添加类似于此的group变量(如果使用ggplot,这会更好)。

代码语言:javascript
复制
df <- rbind(d, dt2)
df$group <- gl(2, 10)

ggplot(data=df, aes(x=Recall, y=Precision, group=group))+
    geom_point(size=2)+
        geom_line(sise=10)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30607588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档