如何删除面板标题并在点图上添加点

时间:2016-07-06 02:37:18

标签: r label lattice points

我有两个数据框:

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添加为现有情节的点

1 个答案:

答案 0 :(得分:2)

设置strip=FALSE以取消&#39;面板标题&#39;。然后,在确保两个data.frames中的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))

enter image description here