ggplot2中的多个图层具有不同的数据集 [英] Multiple layers in ggplot2 with different datasets

查看:791
本文介绍了ggplot2中的多个图层具有不同的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个等高线图,我想用一组不同的数据添加一个geom_path。



现在我有下面的代码,但是作为一旦它进入geom_path,它就会覆盖等高线图。有没有办法来防止这种情况发生?

  v < -  ggplot(pts,aes(theta_1,theta_2,z = z))
v + stat_contour(aes(color = ..level ..),bins = 50)+ xlab(expression(Theta [1]))+ ylab(expression(Theta [2]))
v + geom_path(aes(x = x,y = y,z = z),data = some.mat)




  v < -  ggplot 

(ats(color = ..level ..),bins = 50)+ xlab(表达式(theta [1]))(ats(theta_1,theta_2,z = z))
v <-v + stat_contour )+ ylab(expression(Theta [2]))
v + geom_path(aes(x = x,y = y,z = z),data = some.mat)


I have a contour plot and I would like to add a geom_path with a different set of data over it.

Right now I have the below code, but as soon as it gets to the geom_path, it overwrites the contour plot. Is there a way to prevent this from happening?

v <- ggplot(pts, aes(theta_1, theta_2, z = z))
v + stat_contour(aes(colour = ..level..),bins=50) + xlab(expression(Theta[1])) + ylab(expression(Theta[2]))
v+geom_path(aes(x=x,y=y,z=z), data=some.mat)

解决方案

probably you can do by:

v <- ggplot(pts, aes(theta_1, theta_2, z = z))
v <- v + stat_contour(aes(colour = ..level..),bins=50) + xlab(expression(Theta[1])) + ylab(expression(Theta[2]))
v + geom_path(aes(x=x,y=y,z=z), data=some.mat)

这篇关于ggplot2中的多个图层具有不同的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆