2013-07-25 51 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)) 

您也可以尝试旋转标签。