I have a line graph using ggplot2 with three lines (with variable names, say, 'A', 'B' and 'C' in my data frame). I want to add a geom_smooth using method=loess
, but I want to add the regression line based on the minimum of 'B' and 'C'. Is there a way to do this?
To illustrate, here's a mock code:
names <- c('n1', 'n2', 'n3', 'n4', 'n5')
aline <- c(0.18, 0.21, 0.23, 0.20, 0.16)
bline <- c(0.50, 0.40, 0.30, 0.20, 0.10)
cline <- c(0.14, 0.20, 0.30, 0.35, 0.33)
min_bc <- c(0.14, 0.20, 0.30, 0.20, 0.10)
df <- data.frame(name, aline, bline, cline)
df.m <- melt(df)
g <- ggplot(df.m, aes(group=1, names, value, colour=variable))
g <- g + geom_line(aes(group=variable))
g <- g + geom_point(aes(colour=variable), alpha=0.4)
I want to add a regression line using aline
and min_bc
, without actually plotting min_bc
.
Additionally, I would like to throw this in: In general, I may have some data, and I want to want to plot (in the same graph) different lines (or points, bars, etc.) using different transformations of the data. Is there any comprehensive document where I can get the broad picture of how to do such things in R/ggplot?
aline ~ min_bc
(or maybe the reverse)? – jorandata
andaes(x=..., y=...)
arguments within any ggplot object. – Señor O