# 1 # Import the data - you know how :-) # 2 hist(lettuce$harv.days[lettuce$leaf.col=="red"], main="Green lettuce") hist(lettuce$harv.days[lettuce$leaf.col=="green"], main="Green lettuce") # 3 library(ggplot2) # Loading the ggplot 2 package ggplot(data=lettuce, mapping=aes(x=leaf.col, y=harv.days))+ # specification of the data for plotting geom_boxplot()+ # plotting the boxplot theme_classic() # setting the nice (i.e. I like it) classic theme # 4 ggplot(data=lettuce, mapping=aes(x=leaf.col, y=harv.days))+ # specification of the data for plotting geom_boxplot(fill="lightblue")+ # plotting the boxplot with lightblue fill of the boxes theme_classic() # setting the nice (i.e. I like it) classic theme # 5 ggplot(data=lettuce, mapping=aes(x=leaf.col, y=harv.days, fill=leaf.col))+ # # specification of the data for plotting. Note the fill # parameter pointing to the leaf.col variable geom_boxplot()+ # plotting the boxplot scale_fill_manual(values=c("darkgreen", "red"), name="Leaf color")+ #setting the color palette and legend title theme_classic() # 6 ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass))+ geom_point() # Simple scatterplot ggplot(lettuce, aes(x=harv.days, x=harv.mass))+ geom_point()+ # Simple scatterplot theme_classic()+ #Classic theme (nicer) labs(x = "Harvest days", y = "Harvest mass (g)") #Defining the axis labels #7 ggplot(lettuce, aes(x=harv.days, y=harv.mass, color=leaf.col))+ geom_point()+ # Simple scatterplot theme_classic()+ #Classic theme (nicer) scale_color_manual(values=c("darkgreen", "red"), name="Leaf color")+ # Setting the color palette and the legend title labs(x="Harvest days", y="Harvest mass (g)")#Defining the axis labels #8 ggplot(lettuce, aes(x=harv.days, y=harv.mass))+ geom_point()+ theme_bw()+ # BW theme is another option to make nice graphs facet_wrap(~leaf.col)+ # Definition of the facets by the leaf.col variable labs(x="Harvest days", y="Harvest mass (g)")#Defining the axis labels #9 ggplot(lettuce, aes(x=harv.days, y=harv.mass))+ geom_point(size=3)+ # Increasing the point size three times theme_bw()+ labs(x="Harvest days", y="Harvest mass")+ facet_wrap(~leaf.col) #10 ?ggsave ggsave("scatter.facettes.png", width=6, height=4, dpi=300) ggsave("scatter.facettes.pdf", width=6, height=4) # 11 library(readxl) beer<-read_excel("beer.xlsx") ggplot(beer, aes(x=subtype, y=ABV,fill=type))+ geom_boxplot()+ theme_bw()+ # BW theme labs(x="Beer subtype", y="Alcohol by volume (%)", )+ #Defining the axis labels scale_fill_manual(values=c("brown","orange"), name="Beer type") # Definition of colors for boxplot fills # 12 ggplot(beer, aes(x=type, y=IBU,fill=color))+ geom_boxplot()+ theme_bw()+ # BW theme labs(x="Beer type", y="IBU", )+ #Defining the axis labels scale_fill_manual(values=c("darkgrey","orange","brown","gold"), name="Beer color") # Definition of colors for boxplot fills