[R] y axis in a stacked bar plot

Michelle Simon M.Simon at har.mrc.ac.uk
Wed Mar 25 18:14:40 CET 2015

Below is some simple R code I have used to create a stacked bar chart.  However the y-axis tick marks do not reflect the data.  The minimum and maximum data values I have are 3073351 and 66425013 respectively but the graph has data from 0 and the maximum is different  Data file is attached.  What am I doing wrong?  Please help as I cannot be sure the data is represented correctly in the graph (attached).

fn <-"~/Documents/chr7Data.txt"
x<-read.table(fn,check.names = TRUE, header=T)
d <- data.frame(x)
theChart<-ggplot(d, aes(x=factor(Congenic),y=Position, fill=Strain, theme_rect="white")) + geom_bar(stat='identity', position = "stack" ) + scale_fill_manual(values=c("deepskyblue1", "red2", "green3", "steelblue4", "lightblue4", "gray70")) + ylab(c("Position"))+
ggtitle("Strain specific SNP distribution in the congenics") +

#coord_cartesian(ylim = c(min(d$Position), max(d$Position))) +
#scale_y_continuous(breaks=seq(0, 200000000, 50000000)) +
theme(plot.title = element_text(size=23),
                axis.text.x = element_text(size=13, angle=90),    #20 before
                axis.text.y = element_text(size=13),
                panel.border = element_rect(colour="BLACK",size=0.5),
                axis.title.x = element_text(size=12),
                axis.title.y = element_text(size=12,angle = 90),
                panel.background = element_rect(fill="transparent"),
                #plot.background = element_rect(fill = "transparent",colour = NA)

Many thanks,

This email may have a PROTECTIVE MARKING, for an explanation please see: http://www.mrc.ac.uk/About/Informationandstandards/Documentmarking/index.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sendToRGrp.png
Type: image/png
Size: 83252 bytes
Desc: sendToRGrp.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150325/a01abb3d/attachment-0001.png>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: chr7Data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150325/a01abb3d/attachment-0001.txt>

More information about the R-help mailing list