[英]Bars position in ggplot2
我正在使用ggplot
繪制圖形,但無法減少條形圖之間的間距。 我只能通過增加條形圖的大小來做到這一點,但我希望它們變薄並且離它不遠。
我用了position_dodge(width = 0.5)
但對我沒有幫助。
我的劇本
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)
也許您的問題可以通過更改輸出窗口大小而不是在ggplot
函數中調整代碼來更好地回答:
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)
如果將其輸出為pdf或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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.