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?
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With