向上移动条形图或向下移动图例

时间:2014-11-11 09:37:33

标签: r bar-chart

我想让我的情节尽可能好。我在xaxis上发现了标签问题。它与图表上的图表名称重叠。

这是我使用的代码:

tbl_EOD$location_subacon <- gsub("(.*),.*", "\\1", tbl_EOD$location_subacon)

dataToPlot<-table(tbl_EOD$location_subacon)
cols <- c("blue", "red", "orange", "yellow", "purple", "green", "black", "pink", "indianred", "brown") 
par(las=2)
barplot(dataToPlot, col=cols, main="Subcellular localization",
        xlab="Name of compartment",
        ylab="Number of identified proteins",
        cex.names = 0.80) 

可重复的例子:

> dput(dataToPlot)
structure(c(927L, 29L, 155L, 8L, 162L, 178L, 91L, 90L, 666L, 
33L), .Dim = 10L, .Dimnames = structure(list(c("cytosol", "endoplasmic reticulum", 
"extracellular", "golgi", "mitochondrion", "nucleus", "peroxisome", 
"plasma membrane", "plastid", "vacuole")), .Names = ""), class = "table")

图表:

Chart

我尝试使用cex.names,但在我的情况下我觉得它没那么有用。

1 个答案:

答案 0 :(得分:2)

使用par(mai)更改边距大小,然后将x轴标签留空,然后使用mtext在适当距离(即line)处添加轴标签剧情。类似的东西:

par(mai=c(2,1,1,1))
barplot(dataToPlot, col=cols, main="Subcellular localization",
        xlab="",
        ylab="Number of identified proteins",
        cex.names = 0.80) 
mtext("Name of compartment", side=1, line = 7, las=1)

enter image description here