将点放在合适的geom_smooth上

时间:2016-02-10 15:51:17

标签: r ggplot2

我有以下数据。

> dput(testdat)
structure(list(Type = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Saline", 
"Compound1"), class = "factor"), Treatment = structure(c(1L, 
2L, 3L, 4L, 6L, 5L), .Label = c(".0032uM", ".016uM", ".08uM", 
".4uM", "2uM", "10uM"), class = "factor"), Peak = c(1071.28430020209, 
1458.23366806524, 2714.49856342393, 3438.83453920159, 3938.86391759534, 
2980.10159109856), Area1 = c(3312.99749863082, 4798.35142770291, 
9044.21362002965, 11241.1497514069, 11575.3444645068, 9521.69011119236
), SS1 = c(781.759834505516, 1191.6273298958, 2180.02082601411, 
2601.33855989239, 2492.11886600804, 2185.39715502702), Conc = c(0.0032, 
0.016, 0.08, 0.4, 10, 2), logconc = c(-2.49485002168009, -1.79588001734408, 
-1.09691001300806, -0.397940008672038, 1, 0.301029995663981), 
    Conc_nm = c(3.2, 16, 80, 400, 10000, 2000), logconc_nm = c(0.505149978319906, 
    1.20411998265592, 1.90308998699194, 2.60205999132796, 4, 
    3.30102999566398)), .Names = c("Type", "Treatment", "Peak", 
"Area1", "SS1", "Conc", "logconc", "Conc_nm", "logconc_nm"), row.names = 2:7, class = "data.frame")

我使用以下代码使用nls回归拟合数据(峰值):

fit = nls(Peak ~ SSlogis(logconc_nm,Asym,xmid,scal),data=testdat)

这给了我一个很好的契合度,我很满意,所以我将剂量反应绘制如下:

m <- coef(fit)
vallog <- as.numeric(format((m[3]),dig=4))
val =round(10^val,2)

ggplot(data = testdat,aes(logconc_nm,Peak))+
  geom_point()+
  scale_x_log10(breaks=round(testdat$logconc_nm,2))+
  geom_smooth(method = 'nls',
             formula = y ~ SSfpl(x,A,B,xmid,scal),se=FALSE)+
  geom_vline(color='red',xintercept = vallog,alpha=.5)+
  geom_text(aes(x=vallog,y=max(Peak),label = paste0('EC50',val,'nM')),color='red')#,angle=90)

enter image description here

我的问题是:

我怎样才能添加一个大的&#39;蓝线和红线相交的蓝线上的红点。我想用红点代替红线的需要。我知道我必须使用geom_point,但因为它是一条合适的线,我不能说x = vallog可以吗?

0 个答案:

没有答案