I am running a series of ggplot() calls to create weekly breakdowns of fantasy baseball matchups for various categories. These use geom_bar(). It currently looks like this:
The problem is that I would like this OBP (on base percentage) plot to be considerably narrower in view–in other words, instead of a x-axis minimum value of 0, having an x-axis minimum value of .259 (the smallest value in the dataset for OBP).
However, when I add a limits call to scale_x_continuous(), it gives a warning of “Removed 12 rows containing missing values (geom_bar).” Code is below. Any ideas on how to set an axis limit while using geom_bar()?
dta2 <- subset(dta1,Category=="OBP")
obpmin <- min(dta2$Count)
obpmax <- max(dta2$Count)
OBP <- ggplot(dta2,aes(x=Count,y=reorder(Team_Opp,Count),fill=WLD))+
geom_bar(position="dodge",stat="identity")+
eval(parse(text=paste("scale_x_continuous(expand=expansion(0,0),limits=c(",obpmin,",",obpmax,"))",sep="")))+
theme_bw()+
theme(plot.title=element_text(hjust=0.5),
panel.grid.major.y=element_blank(),
panel.grid.minor.y = element_blank())+
scale_fill_manual(name="",
values=c("Win" = "#56B4E9",
"Draw" = "#009E73",
"Loss" = "#D55E00"))+
xlab("OBP")+
ylab("")
The issue does not seem to relate to the use of obpmin and obpmax, since even when I enter the limits manually (code below), it gives the warning message that it removed the 12 bars for containing missing values.
OBP <- ggplot(dta2,aes(x=Count,y=reorder(Team_Opp,Count),fill=WLD))+
geom_bar(position="dodge",stat="identity")+
scale_x_continuous(expand=expansion(0,0),limits=c(.259,.362))+
theme_bw()+
theme(plot.title=element_text(hjust=0.5),
panel.grid.major.y=element_blank(),
panel.grid.minor.y = element_blank())+
scale_fill_manual(name="",
values=c("Win" = "#56B4E9",
"Draw" = "#009E73",
"Loss" = "#D55E00"))+
xlab("OBP")+
ylab("")