#1 library(readxl) lettuce<-read_excel("lettuce.xlsx") summary(lettuce) lettuce<-read.delim2("clipboard") #2-4 graphics.off() # png("histogram.png", width=1800, height=1200, res=300) pdf("histogram.pdf", width=6, height=4) par(mfrow=c(1,2)) hist(lettuce$harv.days[lettuce$leaf.col=="green"], main=NULL, xlab="Harvest days", ylim=c(0, 20), xlim=c(50, 70), col="green") hist(lettuce$harv.days[lettuce$leaf.col=="red"], main=NULL, xlab="Harvest days", ylim=c(0, 20), xlim=c(50, 70), col="red") dev.off() #5 par(mfrow=c(1,1)) #6 install.packages("ggplot2") library(ggplot2) names(lettuce) ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass))+geom_point()+ theme_classic() #7-8 ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass, col=leaf.col))+geom_point()+ theme_classic()+ scale_color_manual(values=c("darkgreen", "red"), name="Leaf color")+ xlab("Harvest days")+ylab("Harvest mass (g)") #9 ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass))+geom_point()+ facet_wrap(~leaf.col)+ theme_gray()+ xlab("Harvest days")+ylab("Harvest mass (g)") #10 ggplot(data=lettuce, mapping=aes(x=harv.days, y=harv.mass))+geom_point(size=2)+ facet_wrap(~leaf.col)+ theme_gray()+ xlab("Harvest days")+ylab("Harvest mass (g)") #11 ggsave("scatter.png", width = 6,height = 4, dpi = 300) ggsave("scatter.pdf", width = 6,height = 4) install.packages("svglite") library("svglite") ggsave("scatter.svg", width = 6,height = 4) #11 library(ggplot2) ggplot(lettuce, aes(x=leaf.col, fill=as.character(taste)))+ geom_bar(position="stack") ggplot(lettuce, aes(x=leaf.col, fill=as.character(taste)))+ geom_bar(position="dodge") ggplot(lettuce, aes(x=leaf.col, fill=as.character(taste)))+ geom_bar(position="dodge")+ scale_fill_manual(values = c("darkgreen","green", "yellow", "red", "darkred")) #12 ggplot(lettuce, aes(x=leaf.col,y=harv.mass))+ geom_boxplot(fill="lightblue")+theme_classic() #13 ggplot(lettuce, aes(x=leaf.col,y=harv.mass))+ stat_summary(fun.data = mean_se)+theme_classic() library(Hmisc) 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))) summary(big.data) ggplot(big.data, aes(x=fact, y=y))+geom_boxplot() ggplot(big.data, aes(x=fact, y=y))+geom_boxplot()+ scale_y_log10() library(beanplot) beanplot(y~fact, data=big.data, side="both", log="y")