散点图:FUN(X[[i]], ...) 中的错误:找不到对象 'Group'
Scatterplot: Error in FUN(X[[i]], ...) : object 'Group' not found
我正在尝试使用 ggplot 绘制一些数据,但我在重要的线条和星号方面遇到了一些问题。
这是我使用的代码:
p <- ggplot(Hematoxilin_tumor_necrosis, aes(x=total, y=necro, colour = Group))+
labs(y="Necrotic area",x="Total area")+
theme_minimal()
path = data.frame(x=c(78,79,79,78),y=c(22,22,34,34))
p + geom_point(size=0.7)+
geom_smooth(method=lm, se = F, size=0.8) +
scale_color_manual(values=c("#999999","#333333"))+
#Adding asterisks
geom_path(data = path, aes(x = x,y = y)) +
annotate("text",x = 80, y = 27, label="*", cex=7)
这给了我以下错误:
Error in FUN(X[[i]], ...) : object 'Group' not found
我知道问题出在 geom_path(data = path, aes(x = x,y = y))
但我有点迷茫。我是 ggplot 的新手,所以我期待一些简单的问题。
有什么建议吗?
aesthetics
默认继承。 geom_path
试图在 path
数据集上寻找 Group
变量来获取颜色。您应该在 geom_path
:
上使用 inherit.aes = FALSE
geom_path(data = path, aes(x = x,y = y), inherit.aes = FALSE )
我正在尝试使用 ggplot 绘制一些数据,但我在重要的线条和星号方面遇到了一些问题。
这是我使用的代码:
p <- ggplot(Hematoxilin_tumor_necrosis, aes(x=total, y=necro, colour = Group))+
labs(y="Necrotic area",x="Total area")+
theme_minimal()
path = data.frame(x=c(78,79,79,78),y=c(22,22,34,34))
p + geom_point(size=0.7)+
geom_smooth(method=lm, se = F, size=0.8) +
scale_color_manual(values=c("#999999","#333333"))+
#Adding asterisks
geom_path(data = path, aes(x = x,y = y)) +
annotate("text",x = 80, y = 27, label="*", cex=7)
这给了我以下错误:
Error in FUN(X[[i]], ...) : object 'Group' not found
我知道问题出在 geom_path(data = path, aes(x = x,y = y))
但我有点迷茫。我是 ggplot 的新手,所以我期待一些简单的问题。
有什么建议吗?
aesthetics
默认继承。 geom_path
试图在 path
数据集上寻找 Group
变量来获取颜色。您应该在 geom_path
:
inherit.aes = FALSE
geom_path(data = path, aes(x = x,y = y), inherit.aes = FALSE )