0

I have some data here in a .txt file from which I plot the graph below using the following lines of code,

library(scales)
library(ggplot2)
library(reshape2)    

# read data from .txt file into a data frame tdf
write.table(tdf,"multreg.txt",col.names=T,sep="\t") 

# Melt data frame tdf
mlt_tdf <- melt(tdf, id=names(tdf)[1], variable = "cols") 

# Plotting data with corresponding linear regression fits to it
plt_fit <- ggplot(mlt_tdf, aes(x=x,y= value, color=cols)) +
  geom_point(size=2) +
  geom_smooth(method = "lm", se = FALSE,linetype="dashed") +
  scale_y_log10(labels = trans_format("log10", math_format(10^.x))) +   # To display lables in scientific log exponent format without decimal notation for the raised log exponent
  annotation_logticks(sides = "rl") +
  xlim(2,4) +
  theme_bw() + 
  theme(panel.grid.minor = element_blank()) +
  theme(legend.text=element_text(size=14), legend.title=element_text(size=14))+
  theme(axis.text=element_text(size=26)) +
  theme(axis.title=element_text(size=22,face="bold")) +
  labs(x = "x", y = "y") +
  scale_color_discrete(name = "vals", labels = c("+0.1","+0.2","+0.3","+0.4","+0.5","+0.6","+0.7","+0.8","+0.9","+1")) +
  guides(colour = guide_legend(override.aes = list(size=3),nrow=2,title.position = 'top',title.hjust=0.5,legend.direction = "horizontal")) +
  theme(legend.position = 'bottom', legend.margin=unit(0.05,"cm"),legend.background = element_rect(fill ='gray94')) +
  theme(plot.margin=unit(c(0,2,0,0),"mm"))

enter image description here

I would like to extend the limits of the linear fits to the extend until when they intersect as shown here. I tried to increase the x-axis limits + xlim(2,4) but it does not seem to extend the linear fit. I would like to extrapolate the corresponding intersection point and pass it on to a data frame. Could someone suggest how to solve this.

Thanks for the help.

Community
  • 1
  • 1
Amm
  • 1,749
  • 4
  • 17
  • 27
  • 1
    did you try `geom_smooth(fullrange=TRUE,..)` ? – agstudy Feb 13 '14 at 15:34
  • @agstudy Thanks for your suggestion. The limits are extended to the range which is specified for the x-axis limits. I notice that the linear fits does not seem to intersect in this range in the above case. – Amm Feb 13 '14 at 15:39

0 Answers0