Search code examples
rplot

One of my segments won't appear on my plot in Base R


I'm trying to get two segments to meet where they intersect with each other and my logistic curve. I created a data frame of coordinates to create multiple segments but no matter what I do I can only get the vertical line from the x axis to appear on the plot. The only way the horizontal line appears is if i do an abline which isnt ideal. Please help :(

Below is my current code. I've also tried doing it as lines but that doesnt seem to work either.

y_intersection <- predict(BPAPmodel, data.frame(x=ec50))

mult_seg <- data.frame(x0=c(0, ec50),
                       y0=c(y_intersection, y_intersection),
                       x1=c(ec50, ec50),
                       y1=c(y_intersection, 0))

plot(BPAPmodel,
     main="Dose Response - BPAP",
     xlab="Concentration (mg/kg)", ylab="Mortality",
     col="blue", pch=16)
segments(x0=mult_seg$x0, y0=mult_seg$y0, x1=mult_seg$x1, y1=mult_seg$y1, 
         col="red", lty=2)

The only segment that appears


Solution

  • Since your x-axis is logged, the point x = 0 is not plottable. Make your initial x value just a little bit greater than 0 and it will be plottable.