How to expand y axis limit in geom_bar ggplot2

313 views
Skip to first unread message

Abdullah-Al Mamun

unread,
May 31, 2016, 4:04:01 PM5/31/16
to ggplot2

Dear all,

Good day.

I am working to produce geom_bar in ggplot to in x axis I kept both species-culture system (cs) and in y axis % of omega-3 for recommended nutritional intake (RNI). I got four graphs sf1, mn1, fw1, bp1 accordingly but the y axis limit is differ to each other. I tried to add the following three # commands but none of them are working.

Would you please suggest me where I am making the mistakes?   

 

fa<-read.csv("fame.5g.csv")

names(fa)

library ("ggplot2")

qplot(fa)

attach(fa)

cs2<-subset(fa,cs %in%c("FW","HSE","HSSI", "LSSI", "MSE", "MSSI", "Pocket"))

names(cs2) 

sf1<-subset(cs2, Group=="Shellfish")

mn1<-subset(cs2, Group=="Mangrove")

fw1<-subset(cs2, Group=="Freshwater")

bp1<-subset(cs2, Group=="Byproduct")

print(ggplot(aes(x=reorder(Species:cs, RNI), y=RNI, fill=cs), data = cs2) +

        geom_bar(stat="identity") + coord_flip())

print(ggplot(aes(x=reorder(Species:cs, RNI), y=RNI, fill=cs), data = fw1) +

        geom_bar(stat="identity") + coord_flip())

#+expand_limits(y=c(0,60))

#+coord_cartesian(ylim = c(0,60))

#+ scale_y_continuous(limits = c(0,60))

 

Here I would like to expand y axis (RNI) up to 60

 

Sincerely Your's
Abdullah-Al Mamun
PhD Student, Room No. F26
Development Group
School of Natural Science
Institute of Aquaculture
University of Stirling, FK9 4LA, UK
Telephone: 01786466589, Mobile: +447438265137
Email: mamun...@yahoo.com

The University achieved an overall 5 stars in the QS World University Rankings 2015
The University of Stirling is a charity registered in Scotland, number SC 011159.

Brandon Hurr

unread,
May 31, 2016, 4:40:09 PM5/31/16
to Abdullah-Al Mamun, ggplot2
You might want to post an MRE here. scale_x/y_continuous() with limits works just fine on my system. 

qplot(1:10, 1:10) + scale_x_continuous(limits = c(0,60)) + scale_y_continuous(limits = c(0,60))

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages