adding x=y line to hexplot in ggplot2

Hi I am trying to look at different ways to visualize a dataset by using hexplots in ggplot. I essentially want a hexplot with 1. loess line 2. regression line 3.x=y line --> equivalent of abline(0,1)

So far I have come up with this kind of code:

c <- ggplot(mtcars, aes(qsec, wt))
c+stat_binhex()+stat_smooth(method="loess", colour="red")+stat_smooth(method='lm', se=FALSE, colour="orange")+ geom_abline(intercept=0, slope=1)

This gives the picture below, but I still do not see the x=y reference line. Please help. I'm not sure why it is not working. Thanks

enter image description here

1 Answer

The y=x reference line is not inside the coordinate ranges you plot. If you change to

geom_abline(slope=1, intercept=-15)

you will see your line on the plot.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like