2016-07-06 33 views
2

我有两个数据帧:如何删除面板标题,并添加点到晶格积

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

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

希望得到有关如何不标注每个ID建议点添加到现有xyplot(除去面板标题),然后为点添加DF2到现有的情节

+0

感谢Psidom格式化 – user2783615

+0

可能会有所帮助。 http://stackoverflow.com/questions/15803149/how-to-add-points-to-multi-panel-lattice-graphics-bwplot – Psidom

+0

df2是df1的子集,具有相同的值。 df2值将重叠绘制df1值。这是你想要的吗? – DaveTurek

回答

2

设置strip=FALSE打压'小组标题'。然后,小心地确保两个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

+0

非常感谢Josh!精美的作品! – user2783615

+0

@ user2783615很酷。很高兴听到这有帮助! –

相关问题