R ggplot2:“一个;geom_point需要以下缺失的美学:x,y“;

R ggplot2:“一个;geom_point需要以下缺失的美学:x,y“;,r,ggplot2,R,Ggplot2,我面临的问题是,我无法指定线条符号的形状(没有此规范,代码工作正常): 以下是可复制格式的数据(是放入数据框中的效果数据): 以下代码产生错误: library(ggplot2) ggplot(effectdat) + geom_line(aes(varL,fit,linetype=varP)) + theme_bw() + geom_point(aes(shape = varP)) Error: geom_point requires the following missing aesth

我面临的问题是,我无法指定线条符号的形状(没有此规范,代码工作正常):

以下是可复制格式的数据(是放入数据框中的效果数据):

以下代码产生错误:

library(ggplot2)

ggplot(effectdat) + geom_line(aes(varL,fit,linetype=varP)) + theme_bw() + geom_point(aes(shape = varP))

Error: geom_point requires the following missing aesthetics: x, y
我在这里阅读是为了使用
unlist
功能。但是,这会产生另一个错误:

ggplot(unlist(effectdat)) + geom_line(aes(varL,fit,linetype=varP)) + theme_bw() + geom_point(aes(shape = varP))

Error: ggplot2 doesn't know how to deal with data of class numeric

你知道怎么了吗?令我惊讶的是,没有
geom_point()
的函数似乎工作正常。

无需取消列出data.frame。代码如下:

ggplot(effectdat)+geom_线(aes(x=varL,y=fit,linetype=varP))+theme_bw()+geom_点(aes(x=varL,y=fit,shape=varP))


说明:添加了函数所需的缺失美学功能

您正在定义的x和y(
varL
fit
)仅适用于
geom_line()
。或者把它们也放在
geom_point
中,或者更好的是,把它们放在
ggplot
中:
ggplot(effectdat,aes(varL,fit,linetype=varP,shape=varP))+geom_line()+geom_point()+theme_bw()
。这就解决了问题,非常感谢!我现在得到了
警告消息:1:形状调色板最多可以处理6个离散值,因为超过6个值很难区分;你有8个。如果您必须手动指定形状,请考虑手动指定形状。2:删除了包含缺失值(几何点)的10行。
我的理解是,第二个警告是因为x轴上的某些点超过了图形中显示的值,对吗?但是如果是这样,为什么在调用中没有
geom_point()
的情况下不显示此警告?这些警告是相关的,您只能有6个形状,否则不会打印它们。例如:
ggplot(data.frame(x=1:8,y=1),aes(x,y,shape=factor(x)))+geom_point()
我明白了,谢谢!为了确保我理解,删除的10行被理解为:最多6行已打印,8行未打印,每行5行符号,因此2*5=10?是的,我听起来很对。虽然这可能提供了问题的答案,但需要一些解释。请更新答案,并解释此解决方案的工作方式和原因。我的问题已由Axeman在评论中回答,仍然感谢您的贡献!
ggplot(unlist(effectdat)) + geom_line(aes(varL,fit,linetype=varP)) + theme_bw() + geom_point(aes(shape = varP))

Error: ggplot2 doesn't know how to deal with data of class numeric