添加形状美感时,ggplot2 出现对象未找到错误
我正在尝试向现有绘图添加形状美学映射,但收到以下错误。有其他方法可以实现此目的吗?如果我从函数调用中删除 shape=Port
,一切都会按预期工作。
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
数据框w
包含以下数据。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于每个图层都继承默认的 aes 映射,因此当您使用不同的数据集时,需要使 geom_point 中的形状 aes 无效:
Since every layer inherits the default aes mapping, you need to nullify the shape aes in geom_point when you use different dataset: