2016-04-22 4 views
0

Ich habe zwei ggplots wie diese:ggplot2 - Zusammenführung von zwei ggplots in einen Graphen. Strike Zone und Pitch

strike_zones <- data.frame(
    x1 = rep(-1.5:0.5, each = 3), 
    x2 = rep(-0.5:1.5, each = 3), 
    y1 = rep(1.5:3.5, 3), 
    y2 = rep(2.5:4.5, 3), 
    z = factor(c(7, 4, 1, 8, 5, 2, 9, 6, 3)) 
) 

pitcher <- data.frame(
px = c(1.5,2.4, 0, 2), 
pz = c(3,3,3,4.1) 
) 

# Plot example of PITCHf/x strike zone regions 
p <- ggplot() + 
xlim(-4, 4) + xlab("") + 
ylim(0, 6.8) + ylab("") + 
geom_rect(data = strike_zones, 
     aes(xmin = x1, xmax = x2, ymin = y2, ymax = y1), color = "grey") +  theme_bw() + theme(legend.position = "none") 

q <- ggplot(pitcher, aes(x=px,y=pz,color=description)) + geom_point(shape=1) 

Grundsätzlich versuche ich, Tonlagenposition (px als x, und pz als y) zu plotten über die Schlagzone. Es lässt mich nicht und gibt mir Nachricht wie folgt aus:

Error in p + o : non-numeric argument to binary operator 

Zusätzlich: Warnmeldung: Inkompatible Methoden ("+ .gg", "Ops.data.frame") für "+"

Was kann ich tun?

Antwort

1

Statt ganze q der Zugabe von p zu zeichnen, fügen Sie einfach das geometrische Objekt Grundstück p wie folgt

p + geom_point(data = pitcher, aes(x= px, y =pz), shape = 1) 
Verwandte Themen