Dr.R

Laden...

Barplot in R

 

Barplot

Barplots are a good choice to show frequencies of several groups. Also group means +/- standard deviation can be represented by means of the barplot()-function easily.

If you apply the barplot()-function on a matrix object, the bars will be plotted stacked onto each other (beside = FALSE) or grouped next to each other (beside = TRUE).

This video (in German) shows some more examples and explanations: Barplot R

This graphic was created using the following code:

layout(matrix(c(1, 1, 1, 1, 2, 3, 3, 3), ncol = 2))

x <- seq(-20, 10, len = 200)
fn <- 705.87 + 1.201*x + -3.0554*x^2 + -0.10117*x^3

mat <- matrix(fn[-c(51:(51 + 25), (length(fn) - 50):length(fn))], ncol = 3)

y <- apply(mat, 2, mean)
e.bar <- apply(mat, 2, sd)

bp <- barplot(y, ylim = c(0, 800), col = c("palegreen3", "cornflowerblue", "indianred2"), names= c("group1", "group2", "control"), las = 1)
arrows(bp, y + e.bar, bp, y - e.bar, angle = 90, code = 3, col = 1, length = 0.1)

op <- par(mar = c(4, 0, 1, 3))
barplot(mat[1:4, 1:2], horiz = TRUE, col = rev(heat.colors(4)))

plot(1, 1, type = "n", ylim = c(0, 100), xlim = c(0.7 - 0.5, 3.1 + 0.5), axes = F, xlab = "", ylab = "")
polygon(c(0, 4, 4, 0), c(0, 0, 100, 100), col = "powderblue", border = "grey80")
barplot(e.bar, col = "white", axes = FALSE, add = TRUE)
barplot(e.bar, density = c(20, NA, 20), angle = c(45, 45, 135), col = c(1, "white", 1), axes = FALSE, add = TRUE, names = c("Delta01", "MediFun", "RaT-3z"))
for(i in seq(20, 80, 20)) abline(h = i, col = "grey60", lty = 2)
axis(4, las = 1)

par(op)

 

Tags

Barplot, different colours, backgroud colours, error bars, standard error, standard deviation, stacked, horizontal, x-axis, y-axis, bottom, left, top, right, labels, without ggplot, several plots next to each other, multiple plots in one graph, bachelor thesis, master thesis

 

War das hilfreich?

Tags

Barplot, Balkendiagramm, Säulendiagramm, verschiedene Farben, Hintergrundfarbe, Fehlerbalken, Standardfehler, Standardabweichung, gestapelt, horizontal, x-Achse, y-Achse, unten, links, oben, rechts, Beschriftung, ohne ggplot, mehrere Plots nebeneinander, mehrere Plots übereinander, mehrere Plots in einer Grafik, Datenanalyse mit R, Hausarbeit, Bachelorarbeit, Masterarbeit