简体   繁体   中英

restricting Y axis displayed values in ggplot2

Can someone explain why the code below doesn't cut the Y axis off? I am trying to cut off 0 to 50000 and only display values above that. I tried this based on this post

data(iris)
iris2<-iris[,1:4]*5000  

ggplot(data=iris2, aes(x=Sepal.Length, y=Sepal.Width, fill=Sepal.Length)) +
  coord_cartesian(ylim = c(5000, 150000)) +
  geom_bar(stat="identity")

Change your code to:

ggplot(data=iris2, aes(x=Sepal.Length, y=Sepal.Width, fill=Sepal.Length)) + ylim(c(5000, 150000)) +geom_bar(stat="identity")

you only need the ylim, the coord_cartesian is not necessary

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