statistic analysis in R

Importing the fruit production.

data=read.table("tomato.txt",head=TRUE)
attach(data)
data
##   variety rep yield
## 1       A   1    30
## 2       A   2    25
## 3       A   3    28
## 4       B   1    40
## 5       B   2    45
## 6       B   3    38
summary(yield)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   25.00   28.50   34.00   34.33   39.50   45.00
str(data)
## 'data.frame':    6 obs. of  3 variables:
##  $ variety: Factor w/ 2 levels "A","B": 1 1 1 2 2 2
##  $ rep    : int  1 2 3 1 2 3
##  $ yield  : int  30 25 28 40 45 38

boxplot

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.4
box1 <- ggplot(data, aes(variety, yield, fill = variety))+ 
  geom_jitter(width = 0.05) + 
  geom_boxplot()+
  labs(x ="Variety", y = "Yield", title = "Total fruit production") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none")
box1

ggsave("box_exp1.png", width = 7, height=5, dpi = 300)

boxplot2

library(summariser)
## Warning: package 'summariser' was built under R version 3.4.4
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 3.4.4
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: lazyeval
## Warning: package 'lazyeval' was built under R version 3.4.4
## Loading required package: plotrix
## Warning: package 'plotrix' was built under R version 3.4.3
yield<- summarise(group_by(data, variety),
                   mu = mean(yield),
                   sd = sd(yield),
                   n = length(yield),
                   se = sd/sqrt(n),
                   ciu = mu + (qt(0.025, df = n-1)* se),
                   cil = mu - (qt(0.025, df = n-1)* se))
## Warning: package 'bindrcpp' was built under R version 3.4.4
g1<- ggplot(yield, aes(variety, mu, color=variety))+
  geom_point(size=3)+
  geom_errorbar(aes(min = cil, max = ciu), width=0.05, size=1)+
    labs(x ="Variety", y = "Yield", title = "Total fruit production ")+
  theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none")
library(plotly)
## Warning: package 'plotly' was built under R version 3.4.4
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
ggplotly(g1)
ggsave("IC_exp1.png", width = 7, height=5, dpi = 300)

plot

plot(data$yield)

hist(data$yield)

data[data$variety]
##   variety variety.1 variety.2 rep rep.1 rep.2
## 1       A         A         A   1     1     1
## 2       A         A         A   2     2     2
## 3       A         A         A   3     3     3
## 4       B         B         B   1     1     1
## 5       B         B         B   2     2     2
## 6       B         B         B   3     3     3