# Generate a random data set to play with n_obs <- 100 data_set <- data.frame(observation=c(rnorm(n_obs,mean=80,sd=5),rnorm(n_obs,mean=60,sd=5)),population=rep(c("A","B"),each=n_obs)) # # Using the lattice library # Included with R # library(lattice) # Box and whisker plot box_plot <- bwplot(observation ~ population,data=data_set) box_plot$xlab <- "Observation" # Violin plot violin_plot <- bwplot(observation ~ population,data=data_set,panel=panel.violin) violin_plot$xlab <- "Observation" # Denstiy plot density_plot <- densityplot(~ observation,groups=population,data=data_set,auto.key=TRUE) density_plot$xlab <- "Observation" # # Using the ggplot2 library # IMPORTANT : requires installation, is not included with R # Also requires the installation of dependency packages # library(ggplot2) # Box whisker again box_plot_2 <- ggplot(data_set,aes(y=observation,x=population)) + geom_boxplot() + scale_y_continuous("Observation") + scale_x_discrete("Population") # With points box_plot_with_points <- box_plot_2 + geom_jitter() # Density again density_plot_2 <- ggplot(data_set,aes(x=observation,fill=factor(population))) + geom_density(alpha=0.2) + scale_x_continuous("Observation") # Histogram histo_plot <- ggplot(data_set,aes(x=observation,fill=population)) + geom_bar(position="dodge") + scale_x_continuous("Observation")