
Ggplot ( tgc, aes ( x = dose, y = len, colour = supp, group = supp )) + geom_errorbar ( aes ( ymin = len - ci, ymax = len + ci ), colour = "black", width =. 1, position = pd ) + geom_line ( position = pd ) + geom_point ( position = pd ) # Black error bars - notice the mapping of 'group=supp' - without it, the error Ggplot ( tgc, aes ( x = dose, y = len, colour = supp )) + geom_errorbar ( aes ( ymin = len - ci, ymax = len + ci ), width =. 1, position = pd ) + geom_line ( position = pd ) + geom_point ( position = pd ) # Use 95% confidence interval instead of SEM Ggplot ( tgc, aes ( x = dose, y = len, colour = supp )) + geom_errorbar ( aes ( ymin = len - se, ymax = len + se ), width =. Pd <- position_dodge ( 0.1 ) # move them. 1 ) + geom_line () + geom_point () # The errorbars overlapped, so use position_dodge to move them horizontally

Geom_barplot().Ggplot ( tgc, aes ( x = dose, y = len, colour = supp )) + geom_errorbar ( aes ( ymin = len - se, ymax = len + se ), width =. #Let's build a dataset : height of 10 sorgho and poacee sample in 3 environmental conditions (A, B, C) data <- ame( specie= c( rep( "sorgho", 10), rep( "poacee", 10) ), cond_A= rnorm( 20, 10, 4), cond_B= rnorm( 20, 8, 3), cond_C= rnorm( 20, 5, 4) ) #Let's calculate the average value for each condition and each specie with the *aggregate* function bilan <- aggregate( cbind(cond_A,cond_B,cond_C) ~specie, data=data, mean) rownames(bilan) <- bilan bilan <- as.matrix(bilan) #Plot boundaries lim <- 1.2 * max(bilan) #A function to add arrows on the chart error.bar <- function(x, y, upper, lower=upper, length= 0.1.) #Then I calculate the standard deviation for each specie and condition : stdev <- aggregate( cbind(cond_A,cond_B,cond_C) ~specie, data=data, sd) rownames(stdev) <- stdev stdev <- as.matrix(stdev) * 1.96 / 10 #I am ready to add the error bar on the plot using my "error bar" function ! ze_barplot <- barplot(bilan, beside=T, legend.text=T, col= c( "blue", "skyblue"), ylim= c( 0,lim), ylab= "height") error.bar(ze_barplot,bilan, stdev) What’s next? 5, n -1)) # Standard deviation ggplot(my_sum) + geom_bar( aes( x=Species, y=mean), stat= "identity", fill= "forestgreen", alpha= 0.5) + geom_errorbar( aes( x=Species, ymin=mean -sd, ymax=mean +sd), width= 0.4, colour= "orange", alpha= 0.9, size= 1.5) + ggtitle( "using standard deviation") # Standard Error ggplot(my_sum) + geom_bar( aes( x=Species, y=mean), stat= "identity", fill= "forestgreen", alpha= 0.5) + geom_errorbar( aes( x=Species, ymin=mean -se, ymax=mean +se), width= 0.4, colour= "orange", alpha= 0.9, size= 1.5) + ggtitle( "using standard error") # Confidence Interval ggplot(my_sum) + geom_bar( aes( x=Species, y=mean), stat= "identity", fill= "forestgreen", alpha= 0.5) + geom_errorbar( aes( x=Species, ymin=mean -ic, ymax=mean +ic), width= 0.4, colour= "orange", alpha= 0.9, size= 1.5) + ggtitle( "using confidence interval") # Load ggplot2 library(ggplot2) library(dplyr) # Data data % select(Species, Sepal.Length) # Calculates mean, sd, se and IC my_sum % group_by(Species) %>% summarise( n= n(), mean= mean(Sepal.Length), sd= sd(Sepal.Length) ) %>% mutate( se=sd / sqrt(n)) %>% mutate( ic=se * qt(( 1 -0.05) / 2 +. Understand how they are calculated, since they give very different Sometimes without even specifying which one is used.

Three different types of values are commonly used for error bars, Standard deviation, Standard error or Confidence Interval? # Load ggplot2 library(ggplot2) # create dummy data data <- ame( name=letters, value= sample( seq( 4, 15), 5), sd= c( 1, 0.2, 3, 2, 4) ) # rectangle ggplot(data) + geom_bar( aes( x=name, y=value), stat= "identity", fill= "skyblue", alpha= 0.5) + geom_crossbar( aes( x=name, y=value, ymin=value -sd, ymax=value +sd), width= 0.4, colour= "orange", alpha= 0.9, size= 1.3) # line ggplot(data) + geom_bar( aes( x=name, y=value), stat= "identity", fill= "skyblue", alpha= 0.5) + geom_linerange( aes( x=name, ymin=value -sd, ymax=value +sd), colour= "orange", alpha= 0.9, size= 1.3) # line + dot ggplot(data) + geom_bar( aes( x=name, y=value), stat= "identity", fill= "skyblue", alpha= 0.5) + geom_pointrange( aes( x=name, y=value, ymin=value -sd, ymax=value +sd), colour= "orange", alpha= 0.9, size= 1.3) # horizontal ggplot(data) + geom_bar( aes( x=name, y=value), stat= "identity", fill= "skyblue", alpha= 0.5) + geom_errorbar( aes( x=name, ymin=value -sd, ymax=value +sd), width= 0.4, colour= "orange", alpha= 0.9, size= 1.3) + coord_flip()
