0

I want to add a linear regression line to a semi-log dotplot but I can't seem to get it to work.

mm= c(44.637, 41.252, 38.717, 36.176, 34.275, 32.366, 30.676, 29.407, 27.715, 26.866)

bp = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)

ladder = data.frame(mm, bp)

ggplot2.dotplot( data=ladder, xName= 'bp', yName= 'mm', mainTitle='Ladder') + scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x), labels = trans_format('log10',math_format(10^.x)))

I've tried >geom_smooth, >geom_abline, and >stat_smooth. None of these work. Help would be very much appreciated.

1 Answer 1

2

dotplot is not suitable for this data. I think you are looking for scatter plot.

This code worked for me.

ggplot(ladder, aes(bp, mm)) + geom_point() +  
scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x), labels =  trans_format('log10',math_format(10^.x))) +
geom_smooth(method ="lm")

In smooth function, method = "lm" fits a linear regression line

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.