#1 lettuce<-read.csv2("lettuce.csv") summary(lettuce) #2-4 # svg("hist.svg", 7,6) png("hist.png", 7*300,6*300, res=300) par(mfrow=c(2,1)) hist(lettuce$harv.days[lettuce$leaf.col=="red"], main=NULL, xlim=c(50, 70)) hist(lettuce$harv.days[lettuce$leaf.col=="green"], main=NULL,xlim=c(50, 70)) dev.off() #5 par(mfrow=c(1,1)) #6 names(lettuce) library(ggplot2) ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass))+geom_point() ggplot(lettuce, aes(harv.days, harv.mass))+geom_point()+theme_classic() #7 ggplot(lettuce, aes(harv.days, harv.mass, color=leaf.col))+ geom_point()+theme_classic()+ scale_color_manual(values=c("darkgreen", "red"), name="Leaf color")+ labs(x="Harvest days", y="Harvest mass") #8 ggplot(lettuce, aes(harv.days, harv.mass))+ geom_point()+theme_bw()+ labs(x="Harvest days", y="Harvest mass")+ facet_wrap(~leaf.col) #9 ggplot(lettuce, aes(harv.days, harv.mass))+ geom_point(size=3)+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(ggplot2) ggplot(lettuce, aes(x=leaf.col, fill=as.character(taste)))+ geom_bar(position="stack") ggplot(lettuce, aes(fill=leaf.col, x=as.character(taste)))+ geom_bar(position="stack")+ scale_fill_manual(values=c("darkgreen", "red"), name="Leaf color") ggplot(lettuce, aes(x=leaf.col, fill=as.character(taste)))+ geom_bar(position="dodge2") ggplot(lettuce, aes(fill=leaf.col, x=as.character(taste)))+ geom_bar(position="dodge")+ scale_fill_manual(values=c("darkgreen", "red"), name="Leaf color") #12 ggplot(lettuce, aes(x=leaf.col, y=harv.mass))+ geom_boxplot(fill="grey")+theme_classic() #13 ggplot(lettuce, aes(x=leaf.col, y=harv.mass))+ stat_summary(fun.data=mean_se)+theme_classic() ggplot(lettuce, aes(x=leaf.col, y=harv.mass))+ stat_summary(fun.data=mean_cl_normal)+theme_classic() #14 big.data<-data.frame(y=rlnorm(30000, 4, 0.5)+sample(c(1,50, 8, 100, 9, 11, 20, 40, 20), 30000, replace=T), fact=c(rep("a", 12000), rep("b", 18000))) ggplot(big.data, aes(fact, y))+geom_boxplot() ggplot(big.data, aes(fact, log(y)))+geom_boxplot() #17 install.packages("beanplot") library(beanplot) beanplot(y~fact, data=big.data, log="auto") beanplot(y~fact, data=big.data, side="both")