I was working on a task where I'm required to find if there is increase in price while increase in number of rooms. I've used ggplot2
and geom_point
.
But I'm unable to understand is there any increment. Could any one help to make me understand this graph please. Or is there any other way to draw graph so that I can understand easily.
The following line is my code.
ggplot(df, aes(x = rooms, y = price)) geom_point()
CodePudding user response:
Try this - it adds a regression line with confidence interval:
ggplot(df, aes(x = rooms, y = price))
geom_point()
geom_smooth(method = "lm")
CodePudding user response:
What you could do to improve presentation of your data is use geom_jitter
to make the points overlap less. Perhaps you could tweak transparency, too. If you add geom_violin
you could also show the distribution of points. Finally, you can add mean to every level (number of rooms). Something along the lines of
library(ggplot2)
ggplot(mtcars, mapping = aes(x = cyl, y = hp))
theme_bw()
stat_summary(geom = "point", fun.y = mean, aes(group = 1), size = 2, color = "red")
geom_jitter(width = 0.25)