ggplot2 - create different geom_path objects in facets

核能气质少年 提交于 2019-12-13 19:16:41

问题


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)

来源:https://stackoverflow.com/questions/23832847/ggplot2-create-different-geom-path-objects-in-facets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!