CadisEtRama
CadisEtRama

Reputation: 1111

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

Upvotes: 19

Views: 44221

Answers (1)

topchef
topchef

Reputation: 19813

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.

Upvotes: 44

Related Questions