I am trying to add x=y line to my ggplot.

i keep getting this line and its not x=y line.

here is my code:

ggplot(data=compare_df, aes(x=correct_answer, y=average_guess))+

geom_point(aes(col=experiment_type))+

geom_abline()

I am trying to add x=y line to my ggplot.

i keep getting this line and its not x=y line.

here is my code:

ggplot(data=compare_df, aes(x=correct_answer, y=average_guess))+

geom_point(aes(col=experiment_type))+

geom_abline()

Welcome to the community!

Why do you think so? Is it because it doesn't seem to have slope 1?

Note that the scales of the x and y axes are different, and hence it will not maintain a 45 degree angle with the x-axis.

I don't have your data, and hence can't check for myself, but I think `coord_equal`

will be useful.

Hope this helps.

Thank you!

this is not x=y line because when x=39.2 y=less then 25.

i have tried using coord_equal command and its just made the screen look more narrow.

maybe you know how can I make the scales of the x and y axes to be the same?

try adding the slope and the intercept directly in the call for the line:

geom_abline(slope=1, intercept = 0)

But it's strange, I just tested with iris, and there it works fine, even without any parameters.

still doesn't work

ggplot(data=compare_df, aes(x=correct_answer, y=average_guess))+

geom_point(aes(col=experiment_type))+

geom_abline(slope=1, intercept = 0)

When looking at your axis it seems x isn't numeric!

Try adding x=as.numeric(correct_answer) in the first line!?

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.