How to shift bars from y-axis using barplot() R

GW97

I have a barplot with the following code:

bp <- barplot(COL0.matrix,
    beside=T,
    col=col,
    ylim=c(0,100), yaxt="n",
    xlab="Time",ylab="Relative Electrolyte Leakage (%)",
    las=1,xaxt = "n",
    cex.axis=1.5, cex.names= 1.5, font=2, font.lab=2, cex.lab=1.5, family="A", space=c(0,0,1,0), xaxs = 'i')
axis(side=2, family="A", cex.axis=0.8, las=1, font=2, pos=0, tck=c(0), at=c(0,10,20,30,40,50,60,70,80,90,100), labels=c("0", "10","20","30","40","50","60","70","80","90","100"))
axis(side=2, at=c(0,10,20,30,40,50,60,70,80,90,100), labels = c(NA),tcl=c(-0.25),pos=0)
axis(side=2, at=c(0,10,20,30,40,50,60,70,80,90,100), labels = c(NA),tcl=c(0.25),pos=0)
axis(side=1, at=c(1.2, 4.2), labels = c("Dawn", "Dusk"),tck=c(0), family="A", cex.axis=1.5, font=2, pos=0)

This results in the following barplot: Barplot resulting from the above code

I am trying to shift the bars which are right next to the y-axis away. I have tried changing space=(...) but this shifts the whole x-axis so that the x and y axis no longer join.

Is there a way of shifting the left two bars over?

trosendal

You can use the line parameter to move the axis over instead of moving the bars. You want to remove the pos = 0 and define the y title outside the barplot function so you can also control its position. Also you will want to play with the par(mar = ... part so it looks right for your device. For if you save in a pdf device your margin and even the cex parameters probably will need adjusting to make it nice. Also I set the graphics parameter xpd = TRUE to allow the lines function in the last line to plot into the margin space. If you don't do that you'll have a x axis that doesn't meet the y axis. If you don't want that then remove the last line.

COL0.matrix <-  structure(c(71.44109964, 78.43178612, 64.31581642, 70.3339388 ), .Dim = c(2L, 2L), .Dimnames = list(c("Control", "bold(\"Col-0 840g ha\"^\"-1\")" ), c("Dawn", "Dusk")))
col = c("white", "grey70", "white", "grey70")
par(mar = c(5,7,5,5), xpd = TRUE)
bp <- barplot(COL0.matrix,
              beside=T,
              col=col,
              ylim=c(0,100), yaxt="n",
              xlab="Time", ylab = "",
              las=1,xaxt = "n",
              cex.axis=1.5,
              cex.names= 1.5,
              font=2,
              font.lab=2,
              cex.lab=1.5,
              family="A",
              space=c(0,0,1,0),
              xaxs = 'i')

mtext("Relative Electrolyte Leakage (%)", side = 2, font = 2, cex = 1.5, line = 4)

axis(side=2, family="A", cex.axis=0.8,
     las=1, font=2, tck=c(0),
     at=c(0,10,20,30,40,50,60,70,80,90,100),
     labels=c("0", "10","20","30","40","50","60","70","80","90","100"),
     line = 1)
axis(side=2, at=c(0,10,20,30,40,50,60,70,80,90,100), labels = c(NA),tcl=c(-0.25), line = 1)
axis(side=2, at=c(0,10,20,30,40,50,60,70,80,90,100), labels = c(NA),tcl=c(0.25), line = 1)
axis(side=1, at=c(1.2, 4.2), labels = c("Dawn", "Dusk"),tck=c(0), family="A", cex.axis=1.5, font=2, line = 0)
lines(x = c(-0.3, 5.3), y = c(0, 0))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Flip the order of the bars (y axis) in a horizontal barplot() (base R)

R: How to build barplot with multiple bars and dual axis?

R barplot - how to add y axis '%' suffix?

R ggplot2 stacked barplot, percent on y axis, counts in bars

How to create a barplot in R with frequencies on the y-axis not the densities?

How do I manually assign the location of bars along the x-axis using barplot()?

How to shift intersection point of x- and y-axis from 0 to 1 using Python Altair?

How to center bars in R barplot() around ticks

Basic R: move y-Axis for barplot

Barplot: Greek letters on y axis in R

r error bars and y axis labels not in order

Base R barplot: legends showing over the bars and bars are out of the x-axis scale

How to order bars in barplot?

R barplot: how to move x-axis' tick labels farther away from the axis

How to vertically justify text data labels in R barplot along the y-axis?

geom_text in barplot to show frequency over bars using R

How To Create Pyramid Bar Chart in R with y-axis labels between the bars

How to color-code the positive and negative bars in barplot using ggplot

How plot bars on top of grid lines when using barplot?

Grouped barplot in R with error bars

Create a barplot in R with 2 bars

R Barplot: Y-axis cut off at the top?

Barplot ascending by group with partially rescaled y axis in R

How to move y-axis labels away from R plot using lapply in R

Plotting barplot and line from pandas dataframe with different y axis

Rename ticks from y-axis in seaborn.barplot

How do I get all my labels from x-axis shown on R for a barplot?

How to order the bars in a seaborn barplot

How to change the y axis to display percent (%) in Python Plotnine barplot?