2013-07-25 53 views
3

我做了下面的代碼的圖形:Ggplot:如何降低X標籤文本

plot1=ggplot (prot_Hit_selected, aes (x=V2,y=V1)) + geom_bar (stat ="identity", fill="#009E73",colour="black") + theme_bw() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs (title="More representative proteins", x="Protein", y= "Count") + geom_text(aes(label = V3, stat="identity", vjust="1.5")) 

在X軸來表示不同的蛋白質的名字,我得到的麻煩,當這個名字太很長,因爲在圖形中只能看到名稱而不是圖形。除了「打印」更大的圖表,還有什麼辦法可以減少X標籤字符串的字符?

事情是這樣的:

Thisisaveryveryveryloooooongprotein - > Thisisavery [...]

謝謝!

+2

請提出這個問題的可重複性。請參閱[本文](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)以獲取指導。 – SlowLearner

回答

5

嘗試abbreviate功能:

qplot(Species, Sepal.Length, data=iris, geom="boxplot") + 
    scale_x_discrete(label=abbreviate) 

example of label abbreviation

如果違約不會在你的情況下這樣做,你可以定義自己的功能:

qplot(Species, Sepal.Length, data=iris, geom="boxplot") + 
    scale_x_discrete(label=function(x) abbreviate(x, minlength=7)) 

您也可以嘗試旋轉標籤。