将 x 轴放在具有负 y 值的条形图的顶部

Placing an x axis on top of a bar plot with negative y values

我有一些各种实验处理的数据是负值。我想在 bar-plot 的顶部绘制 x-axis 并且标签的位置与传统的 bar-plot 相同,位于条的中心。

我检查了所有地方,但找不到任何可以让我用文字命名轴标签的东西,只能设置刻度线和数字。

这是数据:- "wp_means"

>         12         15          3          6          9    Control 
-0.3000000 -0.2416667 -0.3416667 -0.3916667 -0.2750000 -0.2750000 
        DL 
-0.2833333

这是我绘制 bar-plot 的代码。我可以从它通常的位置省略 x-axis,但我似乎无法将它的标签等放在我想要的位置。

cols<-c("blue1", "cyan","chartreuse","mediumspringgreen","maroon1","orange","red")
    wp<-data.frame(a=c(wp_means),b=c(12,15,3,6,9,"Control","DL"))
    wp$c=factor(wp$b, levels = c("Control",15,"DL",12,9,6,3))
    wp <- wp[order(wp$c), ]
    barplot(height=wp$a,names.arg=wp$c,col=cols,main="Water Potential",las=1,xaxt="n",
    ylab = "Water potential 
    (MPA)",pch=21,bg="black",cex=0.7,cex.lab=0.8,font.lab=2,
    cex.axis=0.7,font.axis=2,cex.main=1,ylim=c(-0.5,0),xaxt="n")

情节是这样的:我想按照上面 "levels = c("Control"....)" 中出现的顺序在上部 x 轴上放置标签。我还想像通常使用 xlab="some name" 一样设置标签标题,而不会干扰我的图表标题。

谢谢

我认为适当的方法是在将 ?axis 添加到现有 barplot 时使用 pos= 参数。但是,您需要先保存条形中心的位置。喜欢bp <- barplot(...),所以:

wp_means <- c(-0.3, -0.2, -0.34, -0.39, -0.275, -0.275, -0.283)

cols<-c("blue1", "cyan","chartreuse","mediumspringgreen","maroon1","orange","red")

wp <-data.frame(a=c(wp_means),b=c(12,15,3,6,9,"Control","DL"))

wp$c=factor(wp$b, levels = c("Control",15,"DL",12,9,6,3))
wp <- wp[order(wp$c), ]
bp <- barplot(height=wp$a, names.arg=wp$c, col=cols, las=1, xaxt="n",
         ylab = "Water potential (MPA)",
         pch=21, bg="black", cex=0.7, cex.lab=0.8, font.lab=2,
         cex.axis=0.7, font.axis=2, cex.main=1, ylim=c(-0.5,0), xaxt="n")

axis(side=3, pos=0, at=bp, labels=levels(wp$c))
title(main="Water Potential", line=3)

请注意在添加 title() 时使用 line=3,这会使您的图表标题远离组标签。