my problem: I want to display two regression lines of different groups/compositions. I just started recently with ggplot and therefore have too little knowledge about regression lines in ggplot.
mel:
composition diametre volume
mixed 0.261 71.3645893
mixed 0.233 392.9487358
mixed 0.319 284.8683927
pure 0.248 120.7654642
pure 0.274 142.1273373
pure 0.308 215.9924244
pure 0.188 26.11804847
pure 0.124 5.795590982
pure 0.307 136.7732086
pure 0.283 138.0600194
pure 0.175 32.43129359
pure 0.205 32.58726466
pure 0.159 12.27308951
The code below displays the scatterplot perfectly well but produces an error when adding geom_smooth (object 'volume' not found);
ggplot(data = mel, aes(x=diametre, y=volume,col=as.factor(composition))) +
geom_point()+
geom_smooth (data = subset(mel, composition=="mixed"), method='lm',
formula= log(volume)~I(diametre^2),
se=FALSE, size=2) +
geom_smooth (data = subset(mel, composition=="pure"), method = "lm",
formula = (volume)~I(diametre^2), se = FALSE, size = 2)
I thought that maybe the error occurs because I am subseting the composition?! So I tried to work with one table for each composition hence the code looked like this
ggplot(data = mel, aes(x=diametre, y=volume,col=as.factor(composition))) +
geom_point()+
geom_smooth (data = mel_mix, method='lm',
formula= log(volume)~I(diametre^2),
se=FALSE, size=2) +
geom_smooth (data = mel_pure, method = "lm",
formula = (volume)~I(diametre^2), se = FALSE, size = 2)
resulting in: invalid argument to unary operator
