2017-08-20 1 views
0

Ich möchte mehrere Datensätze in diesem Diagramm plotten, aber ich kann nicht herausfinden, wie. Ich muss t, u, v, w auf die bereits funktionierende xyplot setzen.Plotten mehr als einen Datensatz in R mit xyplot

library(lattice) 
x <- rnorm(250, 5, .5) 
y <- rnorm(250, 5, .4) 

t <- rnorm(200, 6, .7) 
u <- rnorm(200, 6, .6) 

v <- rnorm(150, 7, .9) 
w <- rnorm(150, 7, .8) 

xyplot(y ~ x, xlab="", ylab="", 
    par.settings = list(axis.line = list(col="transparent")), 
    panel = function(x, y,t,u,...) { 
    panel.xyplot(x, y, col=3, pch=16) 
    panel.rug(x, y, col=8, x.units = rep("snpc", 2), y.units = rep("snpc", 
2), ...)}) 
+0

[ggplot2] (http://ggplot2.tidyverse.org/reference/aes_group_order.html) ist ein einfacher Weg. – Enigma

Antwort

0

Wenn Sie suchen ein Streudiagramm von Punkten, deren Koordinaten zu machen sind definiert durch (x, y), (t, u), & (v, w), die folgende sollte für Sie arbeiten:

df <- data.frame(V1 = c(x, t, v), 
       V2 = c(y, u, w), 
       V3 = c(rep("xy", length(x)), rep("tu", length(t)), rep("vw", length(v)))) 

xyplot(V1 ~ V2, group = V3, data = df, 
     xlab="", ylab="", 
     par.settings = list(axis.line = list(col="transparent")), 
     panel = function(x, y, groups...) { 
     panel.xyplot(x, y, 
         col = c("red", "blue", "green"), # change this if you want other colours 
         pch=16) 
     panel.rug(x, y, col = 8, x.units = rep("snpc", 2), y.units = rep("snpc", 2)) 
     }) 

lattice xyplot

Wenn Sie sie in das Diagramm zeichnen auf andere Weise suchen, bitte in Ihrer Frage klären.