r - 同一个ggplot中的多个线图

标签 r ggplot2

我正在根据这些数据创建折线图。有谁知道如何在同一张图中添加另一条线(带有第二组召回率和精度点)?

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)

最佳答案

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

enter image description here

关于r - 同一个ggplot中的多个线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30607588/

相关文章:

r - 如何在 R 中与 litR 并行处理 LAScatalog

r - 将带有美元符号 ($) 的变量与 facet_grid() 或 facet_wrap() 组合传递给 aes() 时出现问题

r - 在ggplot方面绘制不同值的垂直线

r - 如何在 R 中使用复杂条件减去中位数

R 数据帧将一列子集转换为数据帧(而不是向量)

r - 无法使用 coord_trans 设置限制

r - 将\in(是集合的成员)符号添加到qplot中

r - "Reversed"在 ggplot2 中使用 fct_infreq()

r - 带有 ggplot 的多面热图,用于 X 的选定部分,并带有附加文本标签

r - 有没有办法在R Markdown的嵌入式LaTeX方程中使用r代码的结果