r - Bars position in ggplot2 -
i'm making graph using ggplot
, not able reduce spaces between bars. can increasing size of bars, them become thin , not far away.
i've used position_dodge(width = 0.5)
did not me.
my script
library(scales) seguro <- matrix(0,4,3) seguro <- as.data.frame(seguro) seguro[,1] <- c("2010","2011","2012","2013") seguro[,2] <-c(89,86,87,88) seguro[,3] <-c("89%","86%","87%","88%") names(seguro)[c(1)]<-c("ano") ggplot(seguro, aes(ano, v2, fill=ano))+ geom_bar(width=0.3,stat="identity", position="identity", aes(fill=ano)) + scale_y_continuous(labels=percent) + geom_text(data=seguro,aes(x=ano,label=v3),vjust=0)
perhaps you're question better answered changing output window size, not tweaking code in ggplot
function:
library(scales) seguro <- matrix(0,4,3) seguro <- as.data.frame(seguro) seguro[,1] <- c("2010","2011","2012","2013") seguro[,2] <-c(89,86,87,88) seguro[,3] <-c("89%","86%","87%","88%") names(seguro)[c(1)]<-c("ano") x11(height=7,width=5) ggplot(seguro, aes(ano, v2, fill=ano))+ geom_bar(width=0.3,stat="identity", position="identity", aes(fill=ano)) + scale_y_continuous(labels=percent) + geom_text(data=seguro,aes(x=ano,label=v3),vjust=0)
you can similar things if outputting pdf or jpeg:
pdf("test.pdf",height=7,width=5) ggplot(seguro, aes(ano, v2, fill=ano))+ geom_bar(width=0.3,stat="identity", position="identity", aes(fill=ano)) + scale_y_continuous(labels=percent) + geom_text(data=seguro,aes(x=ano,label=v3),vjust=0) dev.off()
Comments
Post a Comment