-1

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.enter image description here

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()
  • you see that the distributions of the points is the same in all the columns, thus seems that this variable does not influence the response (you can see this by fitting a linear model, you will see that the coefficients are irrelevant) – Alberto Sinigaglia Dec 24 '22 at 22:02
  • 2
    My eyeball analysis is different than Alberto's. Obviously need data but I suspect that a linear regression model with a "test of trend" across values 1:4 as covariates would be highly significant. – IRTFM Dec 24 '22 at 22:30
  • Can you share (a link to) the data? Otherwise there is little we can do ... – kjetil b halvorsen Dec 24 '22 at 23:02
  • 2
    Why `geom_point` and not `geom_boxplot`? Eventually overplotted with `geom_jitter`. – Rui Barradas Dec 25 '22 at 00:12
  • You can achieve statistical significance by adding enough samples. – Roman Luštrik Dec 25 '22 at 12:05

2 Answers2

3

Try this - it adds a regression line with confidence interval:

ggplot(df, aes(x = rooms, y = price)) + 
geom_point() +
geom_smooth(method = "lm")
Grasshopper_NZ
  • 302
  • 1
  • 10
1

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)

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • I've used stat_summary for mean. Here I'm getting increase of mean by the increase of room. However, when I got to the room 5 the mean drop slightly below the mean of 4 rooms. Does that mean there is an increasing trend but because of some reason the price of 5 rooms droped. – Mihrab Miah Dec 25 '22 at 17:09