-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()
5
  • 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) Commented Dec 24, 2022 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. Commented Dec 24, 2022 at 22:30
  • Can you share (a link to) the data? Otherwise there is little we can do ... Commented Dec 24, 2022 at 23:02
  • 2
    Why geom_point and not geom_boxplot? Eventually overplotted with geom_jitter. Commented Dec 25, 2022 at 0:12
  • You can achieve statistical significance by adding enough samples. Commented Dec 25, 2022 at 12:05

2 Answers 2

3

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

ggplot(df, aes(x = rooms, y = price)) + 
geom_point() +
geom_smooth(method = "lm")
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.