散点图:FUN(X [[i]],...)中的错误:找不到对象“组" [英] Scatterplot: Error in FUN(X[[i]], ...) : object 'Group' not found

查看:2517
本文介绍了散点图:FUN(X [[i]],...)中的错误:找不到对象“组"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ggplot 绘制一些数据,但是有效线和星号存在一些问题.

I'm trying to plot some data using ggplot and I'm having some problems with the significant lines and asterisk.

这是我正在使用的代码:

This is the code I am using:

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)

这给了我以下错误:

FUN(X [[i]],...)中的错误:找不到对象'Group'

Error in FUN(X[[i]], ...) : object 'Group' not found

我知道问题出在geom_path(data = path, aes(x = x,y = y)),但我有点迷茫.我是ggplot的新手,所以我期待一些简单的问题.

I know that the problem is in the geom_path(data = path, aes(x = x,y = y)) but I am kind of lost. I am new in ggplot so I expect some simple problem.

有什么建议吗?

推荐答案

aesthetics是继承的. geom_path试图在path数据集上寻找Group变量以获取颜色.您应该在geom_path上使用inherit.aes = FALSE:

aesthetics are inherited by default. The geom_path is trying to look for the Group variable on the path dataset to get the color. You should use inherit.aes = FALSE on the geom_path:

  geom_path(data = path, aes(x = x,y = y), inherit.aes = FALSE )

这篇关于散点图:FUN(X [[i]],...)中的错误:找不到对象“组"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆