Adding X=Y Line to Hexplot in Ggplot2

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

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

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

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.