【问题标题】:Plotting multiple lines R [duplicate]绘制多条线R [重复]
【发布时间】:2013-06-21 10:58:57
【问题描述】:

我有以下数据:

   dim   tuples buckets error is.init
1    5 13500000      50  0.29    TRUE
2    5 13500000     100  0.28    TRUE
3    5 13500000     150  0.27    TRUE
4    5 13500000     200  0.26    TRUE
5    5 13500000     250  0.26    TRUE
6    4   360000      50  0.10    TRUE
7    4   360000     100  0.09    TRUE
8    4   360000     150  0.09    TRUE
9    4   360000     200  0.09    TRUE
10   4   360000     250  0.09    TRUE
11   3     9000      50  0.10    TRUE
12   3     9000     100  0.09    TRUE
13   3     9000     150  0.09    TRUE
14   3     9000     200  0.08    TRUE
15   3     9000     250  0.07    TRUE
16   5 13500000      50  0.48   FALSE
17   5 13500000     100  0.43   FALSE
18   5 13500000     150  0.44   FALSE
19   5 13500000     200  0.44   FALSE
20   5 13500000     250  0.43   FALSE
21   4   360000      50  0.41   FALSE
22   4   360000     100  0.39   FALSE
23   4   360000     150  0.36   FALSE
24   4   360000     200  0.37   FALSE
25   4   360000     250  0.35   FALSE
26   3     9000      50  0.31   FALSE
27   3     9000     100  0.26   FALSE
28   3     9000     150  0.25   FALSE
29   3     9000     200  0.22   FALSE
30   3     9000     250  0.20   FALSE

对于每个暗淡值,我想要两行。第一行在 is.init = T 时显示错误,第二行在 is.init=F 时显示错误。 X 轴是“桶”。 例如,如果所有行“is.init = T”都是虚线,那就太好了。 我该怎么做呢?提前致谢。

【问题讨论】:

  • 构造一个反映is.initdim的新变量。将其用作着色/分组变量。
  • -1 因为你没有表现出任何努力来做这个情节。

标签: r plot ggplot2 lattice


【解决方案1】:

这个问题是重复的,但我试图添加一个lattice 解决方案我发现自定义条形面板并不明显。也许我错过了什么,但这里是我的代码:

library(lattice) 
xyplot(error~buckets|dim,
       groups=is.init,data=dat,type='l',
       auto.key=list(columns = 2),
       strip = function(which.panel,var.name,factor.levels,...)
       {
         strip.default(..., which.panel,factor.levels,
                       var.name = paste0(var.name,factor.levels[which.panel]))
       })

【讨论】:

    【解决方案2】:

    类似:

    library(ggplot2)
    library(reshape2)
    w$new <- paste(w$is.init, w$dim, sep = ".") # I named your data frame w
    ggplot(data = w, aes(x = buckets, y = error, group = new)) +
    geom_line(aes(linetype = is.init), size = 1) + facet_wrap(~dim)
    

    我几乎找到了您需要的确切情节here

    【讨论】:

    • 谢谢。 Buckets 是 x,error 是 y,虚线 - 没有虚线是 init=T 或 false,我可以使用线型/颜色作为维度。
    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2013-06-13
    • 2023-03-12
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    相关资源
    最近更新 更多