简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM