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

时间:2017-07-11 22:37:08

标签: r plot bar-chart axis axis-labels

我有一些数据用于各种实验性治疗,这些数据都是负值。我想在条形图的顶部绘制x轴,并使标签的位置与条形图中心的传统条形图相同。

我已经全部检查过,找不到任何能让我用单词命名轴标签,只设置刻度线和数字的内容。

以下是数据: - “wp_means”

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

这是我绘制条形图的代码。我可以从它通常的位置省略x轴,但我似乎无法将它放在标签等的顶部,我想要它。

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")

这是情节:我希望上面的x轴上的标签按照它们出现在"levels = c("Control"....)"上面的顺序。我也想像xlab="some name"一样设置标签标题,而不会干扰我的图表标题。

由于

enter image description here

1 个答案:

答案 0 :(得分:5)

我认为适当的方法是在向现有public class Person public Store store public class Store public String name public Item item public String location public class Item public String name 添加pos=时使用?axis参数。但是,您需要先保存酒吧中心的位置。与barplot一样,所以:

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) 时使用line=3会将您的图表标题推离群组标签。

enter image description here