2013-06-01 174 views
2

再次卡住了,我想擺脫在y軸和x軸上存在的額外間距。如何避免x軸和y軸上的額外間距

我知道這個間距可以防止某些數據點可能干擾軸,從而降低圖表的可讀性。但現在,我想擺脫在繪圖區中使用的這個空間。

這裏是我的代碼

library(ggplot2) 

df <- data.frame(category = c("A", "B"), value=c(3,4)) 

q <- ggplot(data=df) 
q <- q + geom_bar(aes(x=category, y=value, stat="identity")) 
q 

我想休息就不會工作,因爲這只是一個例子集

sample chart

回答

3
q <- ggplot(data=df,aes(x=category, y=value)) 
q <- q + geom_bar(stat="identity") 
q + scale_x_discrete(expand=c(0,0)) + scale_y_continuous(expand=c(0,0)) 

enter image description here

+0

非常感謝我不得不重讀關於縮放的細節 –