将x轴标签直接放在R中的条形图中的刻度标记下

时间:2017-02-21 09:30:14

标签: r graphics format bar-chart

我有一张表(下图)显示了小组实验中存在的树种(分类变量)的百分比。我的目标是绘制y轴上树种的百分比和物种'在条形图中的x轴上。

enter image description here

问题

我的问题是我遇到了正确格式化x轴的问题。我的目标是确保**' Species' **的x轴标签是: -

  1. 直接位于其标记下方的刻度线
  2. 不要重叠到绘图区域
  3. 如果有人可以帮助解决这个问题,我将非常感激。

    enter image description here

    R代码

      df <- leaf.percent[order(leaf.percent$Leaf.Percentge, decreasing = TRUE),]
    
      Tree.labels<-c("Quercus robar", "Quercus Patraea",
                     "Deciduous", "Oak",
                     "Plant", "Shrub")
    
      par(mar=c(6, 6, 3, 3))
    
      Tree<-barplot(df$Leaf.Percentge, names.arg = df$Species,
                    xaxt = "n",
                    ylab="Percentage %", 
                    xlab="Tree Species",
                    col="lightblue",
                    ylim = c(0, 60))
    
        axis(1, at=Tree, labels=FALSE)
    
        text(seq(1, 6, by=1), par("usr")[3] - 0.2, 
             labels=unique(Tree.labels), 
             srt = 25, pos = 1, 
             xpd = TRUE, cex=0.7)
    

    数据

    structure(list(Species = structure(1:6, .Label = c("Deciduous", 
    "Oak", "Plant", "Quercus_petraea", "Quercus_robur", "Shrub"), class =     "factor"), 
    Frequency = c(48L, 29L, 6L, 70L, 206L, 4L), Leaf.Percentge =     c(13.2231404958678, 
    7.98898071625344, 1.65289256198347, 19.2837465564738, 56.7493112947658, 
    1.10192837465565)), .Names = c("Species", "Frequency", "Leaf.Percentge"
    ), row.names = c(NA, -6L), class = "data.frame")
    

0 个答案:

没有答案