本文介绍了使用ggplot的geom_rug中的不同数据比我在其余的绘图中使用的数据要多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我无法使用geom_rug将某些数据绘制到现有的绘图中。下面是一个示例图,我将一些访问日与某个度量的大小进行比较。 test< - data.frame ( visit = rep(c(0,1.5,3.5,6.5,12),5), mag = rnorm(n = 25)) ggplot(test,aes(x = visit,y = mag))+ geom_point() 以下情节。 我还有一些其他数据,我想只在x轴上添加额外的标记。 vac visit = c(2,4,6,8)) 由于我不明白的原因,当我运行时,下面的代码。 ggplot(test,aes(x = visit,y = mag))+ geom_point()+ geom_rug(data = vac,aes(x = visit)) 我想我已经搞砸了在某种程度上语法,但我似乎无法弄清楚我在这里做错了什么。任何建议?解决方案您应该指定 inherit.aes = FALSE in geom_rug()行,否则它从主 ggplot()继承 y = mag call。 ggplot(test,aes(x = visit,y = mag))+ geom_point()+ geom_rug(data = vac,aes(x = visit),inherit.aes = F) I am having trouble getting geom_rug to plot some data into an existing plot. Here's an example plot, where I am comparing some visit day to the magnitude of some measurement.test <- data.frame( visit = rep(c(0, 1.5, 3.5, 6.5, 12), 5), mag = rnorm(n = 25) )ggplot(test, aes(x = visit, y = mag)) + geom_point()Which generates the following plot.I also have some other data, that I'd like to add just as extra marks on the x axis.vac <- data.frame( visit = c(2, 4, 6, 8) )For reasons I don't understand, I get no plot at all when I run the following code.ggplot(test, aes(x = visit, y = mag)) + geom_point() + geom_rug(data=vac, aes(x = visit))I presume I have messed up on syntax somehow, but I can't seem to figure out what I am doing wrong here. Any suggestions? 解决方案 You should specify inherit.aes = FALSE in the geom_rug() line, otherwise it inherits y = mag from the main ggplot() call.ggplot(test, aes(x = visit, y = mag)) + geom_point() + geom_rug(data=vac, aes(x = visit), inherit.aes = F) 这篇关于使用ggplot的geom_rug中的不同数据比我在其余的绘图中使用的数据要多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 10:43