添加形状审美时,对象未找到与ggplot2的错误 [英] Object not found error with ggplot2 when adding shape aesthetic
本文介绍了添加形状审美时,对象未找到与ggplot2的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将一个形状美学映射添加到现有的情节,但我正在接受下面的错误。有没有不同的方式来完成这一点?如果我从函数调用中移除 shape = Port
,一切都按预期工作。
<$ c (大小= 3,alpha = 0.75)+
scale_colour_gradient(数据= w,aes(OAD,RtgValInt,color = dt,shape = Port))+
geom_jitter (b)(b)(b)(b)(b)(b)(b)限制= c(最小(w $ dt),
最大(w $ dt)),
低=#9999FF,high =#000066 data.frame(OAD = w $ OAD [1],
RtgValInt = w $ RtgValInt [1]),
color =red,size = 3)
print(p)
eval中的错误(expr,envir,enclos):找不到对象'Port'
数据框 w
包括以下数据。
日期Port OAD RtgValInt dt
12/31/2010 Grp1 1.463771 1.833333 14974
12/31/2010 Grp2 1.193307 2.071429 14974
11/30/2010 Grp1 1.454115 1.833333 14943
11/30 / 2010 Grp2 1.127755 2.071429 14943
10/29/2010 Grp1 1.434965 2.000000 14911
10/29/2010 Grp2 1.055758 2.071429 14911
09/30/2010 Grp1 1.441773 2.000000 14882
09/30/2010 Grp2 1.077799 2.071429 14882
$ c $由于每一层都继承了默认的aes映射,所以当你需要在geom_point中使形状aes无效时使用不同的数据集:
p < - ggplot(data = w,aes(OAD,RtgValInt,color = dt,shape = Port))+
geom_jitter(size = 3,alpha = 0.75)+
scale_colour_gradient(limits = c(min(w $ dt),
max(w $ dt)),
low =#9999FF,high =#000066)+
geom_point(aes(shape = NULL),data = data.frame(OAD = w $ OAD [1],
RtgValInt = w $ RtgValInt [1]),
color =red,size = 3)
I am attempting to add a shape aesthetic mapping to an existing plot but am receiving the error below. Is there a different way to accomplish this? If I remove shape=Port
from the function call, everything works as expected.
p <- ggplot(data=w, aes(OAD,RtgValInt,color=dt,shape=Port)) +
geom_jitter(size=3, alpha=0.75) +
scale_colour_gradient(limits=c(min(w$dt),
max(w$dt)),
low="#9999FF", high="#000066") +
geom_point(data=data.frame(OAD=w$OAD[1],
RtgValInt=w$RtgValInt[1]),
color="red", size=3)
print(p)
Error in eval(expr, envir, enclos) : object 'Port' not found
The data frame w
includes the data below.
Date Port OAD RtgValInt dt
12/31/2010 Grp1 1.463771 1.833333 14974
12/31/2010 Grp2 1.193307 2.071429 14974
11/30/2010 Grp1 1.454115 1.833333 14943
11/30/2010 Grp2 1.127755 2.071429 14943
10/29/2010 Grp1 1.434965 2.000000 14911
10/29/2010 Grp2 1.055758 2.071429 14911
09/30/2010 Grp1 1.441773 2.000000 14882
09/30/2010 Grp2 1.077799 2.071429 14882
解决方案 Since every layer inherits the default aes mapping, you need to nullify the shape aes in geom_point when you use different dataset:
p <- ggplot(data=w, aes(OAD,RtgValInt,color=dt,shape=Port)) +
geom_jitter(size=3, alpha=0.75) +
scale_colour_gradient(limits=c(min(w$dt),
max(w$dt)),
low="#9999FF", high="#000066") +
geom_point(aes(shape=NULL), data=data.frame(OAD=w$OAD[1],
RtgValInt=w$RtgValInt[1]),
color="red", size=3)
这篇关于添加形状审美时,对象未找到与ggplot2的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文