ggplot2 - create different geom_path objects in fa

2019-08-04 12:42发布

问题:

First I'll say that I am just learning ggplot2 and this was code I inherited from someone else. I'm using facet_wrap to create two graphs side by side. I'm then using geom_path to draw a shape in each graph, but I want a different shape in each one. Right now I can only get the same shape in each graph, or both shapes in both graphs. So basically need to do something to one facet but not the other.

This is my truncated code:

#variables already defined
square1 <- data.frame(x=c(left, right, right, left, left), 
                y=c(bottom, bottom, top, top, bottom))
square2 <- data.frame(x=c(left2, right2, right2, left2, left2), 
                y=c(bottom2, bottom2, top2, top2, bottom2))

RE <- ggplot(data, aes(x, y))
RE <- RE + geom_point()
RE <- RE + xlab + ylab + ggtitle
RE <- RE + coord_cartesian()
RE <- RE + scale_colour_brewer()
RE <- RE + theme_bw()
RE <- RE + facet_wrap(~ v1 + v2, ncol=2)
RE <- RE + geom_path(aes(x = x, y = y), data = square1) + geom_path(aes(x = x, y = y), data = square2, linetype = 2)