user3565587
user3565587

Reputation: 49

How do I make custom scales on a scatter plot in ggplot2?

I am using the diamonds data set to do some analysis for a project. I need to figure out how to change the x and y scales. When I use this:

library(ggplot2)
ggplot(diamonds, aes(x=carat,y=price))+geom_point()+ylab("Diamond Price")+
xlab("Diamond Cut")

the x scale is 0-5 and the y scale is 1000-5000. How can I change the scale and intervals?

Thanks in advance

Upvotes: 1

Views: 1022

Answers (1)

Shambho
Shambho

Reputation: 3280

Use xlim or ylim:

ggplot(diamonds, aes(x=carat,y=price)) +
  geom_point() + ylab("Diamond Price") +  xlab("Diamond Cut") + 
  ylim(0, 5000) + xlim(0,2)

Upvotes: 1

Related Questions