# set working directory setwd("~/Desktop") # read data dat <- read.csv("plot_sample.csv") # change table #install.packages("reshape") library(reshape) melted <- melt(dat, id = c("treatment", "time")) # plot #install.packages("ggplot2") library(ggplot2) #box plot ggplot(melted, aes(x=as.factor(time), y=value))+ geom_boxplot(aes(fill=treatment),position= position_dodge(0.9))+ labs(x="Time(hr)", y="Concentration (mg/ml)") #+++++++++++++++++++++++++ # Function to calculate the mean and the standard deviation # for each group #+++++++++++++++++++++++++ # data : a data frame # varname : the name of a column containing the variable #to be summariezed # groupnames : vector of column names to be used as # grouping variables data_summary <- function(data, varname, groupnames){ require(plyr) summary_func <- function(x, col){ c(mean = mean(x[[col]], na.rm=TRUE), sd = sd(x[[col]], na.rm=TRUE)) } data_sum<-ddply(data, groupnames, .fun=summary_func, varname) data_sum <- rename(data_sum, c("mean" = varname)) return(data_sum) } df <- data_summary(melted, varname="value", groupnames=c("treatment", "time")) p <- ggplot(df, aes(x=time, y=value, fill=treatment)) + geom_bar(stat="identity", position=position_dodge()) + geom_errorbar(aes(ymin=value-sd, ymax=value+sd), width=.2, position=position_dodge(.9)) plot(p)