【问题标题】:How to plot a graph in lattice based on columns如何根据列在格中绘制图形
【发布时间】:2015-01-06 17:06:51
【问题描述】:

我有一个这样的数据框:

epochs   lm      le    kd
-------|-------|------|----
1      | 0.38  | 0.25 | 0.21
2      | 0.34  | 0.22 | 0.44
3      | 0.45  | 0.33 | 0.22

我想使用lattice 中的xyplotlmlekd 的交互来绘制此图。 X 轴为epochs,Y 轴的范围为 0.10 到 0.60(取决于数据)

我在下面尝试过,但它不起作用,因为我不知道在 Y 轴上放什么?

xyplot(epochs ~ 'whattoputhere??', data=data, +组=粘贴(“Le =”,le,“lm =”,lm,“kd =”,kd), + 类型 = "l", + 自动键 = + 列表(空格 =“右”,点 = FALSE,行 = TRUE))

【问题讨论】:

    标签: r lattice


    【解决方案1】:

    通常,格函数会更容易与“长数据”一起使用,而不幸的是,您的函数是“宽数据”。 melt 函数是送给 R 用户的好礼物(谢谢,Hadley)。

    > dat <- read.table(text="epochs |  lm   |   le  |  kd
    + 1      | 0.38  | 0.25 | 0.21
    + 2      | 0.34  | 0.22 | 0.44
    + 3      | 0.45  | 0.33 | 0.22", header=TRUE,sep="|")
    > require(reshape2)
    Loading required package: reshape2
    
    > datm <- melt(dat, id.var="epochs")
    > str(datm)
    'data.frame':   9 obs. of  3 variables:
     $ epochs  : num  1 2 3 1 2 3 1 2 3
     $ variable: Factor w/ 3 levels "lm","le","kd": 1 1 1 2 2 2 3 3 3
     $ value   : num  0.38 0.34 0.45 0.25 0.22 0.33 0.21 0.44 0.22
    
    xyplot(value ~ epochs, groups=variable, datm, type="b",  
             auto.key =  list( space="right", points = FALSE, lines = TRUE) )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-21
      • 2018-08-18
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 2021-08-05
      相关资源
      最近更新 更多