Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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)

Which gives me the following error:

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

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.

Any advice?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...