I have a df:
MixA<-c(11.3296500, 3.7765500, 13.2179250, 1.8882750, 60.4248063, 906.3720938, 483.3984500, 1450.1953500, 0.4130875, 0.0590125)
TPM<-c(496.510998, 121.020332, 32.194033, 0.584421, 63.569152, 253.681165, 0.000000, 30487.460466, 0.000000, 0.000000)
test<-data.frame(MixA,TPM)
I want to log so I arbitarily replace the zeros and I want to plot these 'zero' points in a seperate colour so I group the data:
test[test == 0]<-0.01
test$group<-as.factor(ifelse(test$TPM==1.000000e-02,0,1))
When I plot with ggplot and it plots a lm for both groups but I want to remove the lm for the 'zero' group.
ggplot(test, aes(x=log10(test$MixA),y=log10(test$TPM),color=group)) + geom_point(size=3) +
geom_smooth(method=lm) + scale_x_continuous(limits=c(-2.5, 3)) + scale_y_continuous(limits=c(-2.5, 5)) +
theme(legend.position = "none")
I tried adding aes(group=1) to geom_smooth but this seems to shift the whole line??:
ggplot(test, aes(x=log10(test$MixA),y=log10(test$TPM),color=group)) + geom_point(size=3) +
scale_x_continuous(limits=c(-2.5, 3)) + scale_y_continuous(limits=c(-2.5, 5)) +geom_smooth(aes(group=1), method="lm")+
theme(legend.position = "none")
filter
the data and then plot ?test %>% filter(group != 0) %>% ggplot() + aes(x=log10(MixA),y=log10(TPM),color=group) + geom_point(size=3) + geom_smooth(method=lm) + scale_x_continuous(limits=c(-2.5, 3)) + scale_y_continuous(limits=c(-2.5, 5)) + theme(legend.position = "none")
– Ronak Shah