0

我在 .txt 文件中有一些数据,我使用以下代码行绘制了下面的图表,

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"))

在此处输入图像描述

我想将线性拟合的限制扩展到延伸,直到它们相交,如此处所示。我试图增加 x 轴限制+ xlim(2,4),但它似乎并没有扩展线性拟合。我想推断相应的交点并将其传递给数据框。有人可以建议如何解决这个问题。

谢谢您的帮助。

4

0 回答 0