【问题标题】:how to remove panel title and add points onto lattice plot如何删除面板标题并将点添加到格点图上
【发布时间】:2016-07-06 02:37:17
【问题描述】:

我有两个数据框:

df1 <- read.table(text = "
Time    Score   ID
 -83       19   C1
 -69       17   C2
 -55       15   C3
 -28       22   C4
   0       27   C5", header=TRUE)

df2 <- read.table(text = "
Time    Score   ID
 -83       19   C1
 -55       15   C3
   0       27   C5", header=TRUE)

我想用 df1 创建一个 xyplot,按 ID 分组,但不标记每个 ID。然后使用来自 df2 的点向现有 xyplot 添加点

library(lattice)
xyplot(df1$Score ~ df1$Time | df1$ID, type ="b", cex = .5)

不胜感激有关如何不标记每个 ID(删除面板标题)然后将 df2 作为点添加到现有绘图的建议

【问题讨论】:

标签: r label lattice points


【解决方案1】:

设置strip=FALSE 以抑制“面板标题”。然后,在确保两个 data.frame 中的 ID 因子水平匹配后,您可以使用 latticeExtra::as.layer() 将来自第二个 data.frame 的数据绘制到使用第一个构建的图上:

library(latticeExtra)

## Fiddly bit needed to make sure, e.g., that level `C3` is coded 
## using the same number (here a '3') in both ID columns.
df2$ID <- factor(df2$ID, levels = levels(df1$ID))

## Plot data from both data.frames onto the same plot
xyplot(Score ~ Time | ID, data = df1, type ="b", cex = .5, strip = FALSE) + 
as.layer(xyplot(Score ~ Time | ID, data = df2, type ="b", 
                cex = 5, drop.unused.levels = FALSE))

【讨论】:

  • 非常感谢乔希!效果很好!
  • @user2783615 酷。很高兴听到这有帮助!
猜你喜欢
  • 2012-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-23
  • 2012-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多