0

I've been trying to figure out how to replace the x-axis in gap.barplot in R. First, I have an issue with labeling:

Attached is my code:

Samples     Conc    stdlo   stdhi
SampA        5000      0    0
SampB        100       0    11
SampC           80     0    20


rm(list=ls())
library(plotrix)

C.dat <- read.csv("G:/...../C.csv", head = TRUE)
C.lab = C.dat$Samples
C.conc = C.dat$Conc
C.lostd = C.dat$stdlo
C.histd = C.dat$stdhi

par(mar=c(6,6,5,2))

barplot = gap.barplot(C.conc, gap = c(200,1000), xlab = "Samples", 
ylab ="C Conentration (pg/mL)", main = "C in X and Y", las = 2,
xlim = c(0,4), ytics = c(0,1000,1500,5100), cex.lab = 1.5)

mtext("SampA", side = 1, at= 1.0, cex=1.0)
mtext("SampB", side = 1, at= 2.0, cex=1.0)
mtext("SampC", side = 1, at= 3.0, cex=1.0)

arrows(barplot,C.conc-0 ,barplot,C.conc+C.histd,code=2,angle=90,length=.1)

My biggest issue is when I stick in axes = FALSE in the gap.barplot parameters, it gives me a warning and no plot is produced. I want to get rid of the "1 2 3" axes label and the tick marks.

Also, if anyone has any idea how to move the y-axis label a bit more to the left, that would be nice.

Any suggestions?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
crazian
  • 649
  • 4
  • 12
  • 24

1 Answers1

1

You may try this. I call your data frame df.

I added xaxt = "n" to the gap.barplot call.
From ?par: xaxt: A character which specifies the x axis type. Specifying "n" suppresses plotting of the axis.

Then axis is used to add an x axis with labels at positions at, but with no ticks (tick = FALSE). The label for the y axis is added with mtext

library(plotrix)
par(mar=c(6,6,5,2))

gap.barplot(df$Conc, gap = c(200,1000),
            xlab = "Samples", ylab ="", main = "C in X and Y", las = 2,
            xlim = c(0, 4), ytics = c(0, 1000, 1500, 5100), cex.lab = 1.5,
            xaxt = "n")

axis(side = 1, at = seq_along(df$Sample), labels = df$Sample, tick = FALSE)
mtext("C Concentration (pg/mL)", side = 2, line = 4)

enter image description here

Henrik
  • 65,555
  • 14
  • 143
  • 159