1

I have the following data.

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

I've fitted the data (Peak) with a nls regression using the following code:

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

This gives me a nice fit and I'm happy with it so I plot the dose response as follows:

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

My Question is:

How can I add a big ol' red point on the blue line where the blue and red line meet. I'd like to replace the need for the red line with the red dot. I know i have to use geom_point but because it's a fitted line, i can't just say x=vallog can i?

Ted Mosby
  • 1,426
  • 1
  • 16
  • 41
  • 5
    Use the fitted model to find the predicted value at that x value and then plot that point. – joran Feb 10 '16 at 15:56
  • Does this post help? http://stackoverflow.com/questions/9789871/method-to-extract-stat-smooth-line-fit – Mist Feb 11 '16 at 09:15
  • it does help. I can't say it's worth my trouble to add it in to my code. the straight line seems to make other happy in my department so thats what we are sticking with. but it's good to know for future reference! – Ted Mosby Feb 11 '16 at 14:57

0 Answers0