Here is the data I want to plot. I want to make grouped bar graph as shown below.I am using lattice package for making my grouped bar graph.
library (readxl)
cd8 <- read_excel("C:/Users/lokra_000/Desktop/IFN_antibody_optimization.xlsx",
sheet = "CD8")
head(cd8)
## # A tibble: 6 x 3
## Primary `1:100 dilution` `1:200 dilution`
## <chr> <dbl> <dbl>
## 1 No_antiboody 0 0.011
## 2 2 ul /mL 1.94 0.027
## 3 4 ul/mL 2.49 2.84
## 4 8 ul/mL 2.87 3.59
## 5 10 ul/mL 3.35 3.25
## 6 12 ul/ml 3.52 3.39
library (lattice)
barchart(cd8$Primary~ cd8$`1:100 dilution`+cd8$`1:200 dilution`,labels=T,draw.labels=T,
scales=list(x=list(rot=90,cex=0.8)),xlab="No of CD8 Cells")
Here you can see that labels in the y axis are not ordered properyly. This makes it difficult to visualize the data. Easy solution to this problem would be to provide levels to the values so that R knows which order to follow. To use level fucntion we have to fist convert this variable to the factor and then indicate the labels we want to follow
cd8$Primary<- factor(c("No_antiboody","2 ul /mL","4 ul/mL", "8 ul/mL","10 ul/mL", "12 ul/ml","16 ul/mL"), levels=c("No_antiboody","2 ul /mL","4 ul/mL", "8 ul/mL","10 ul/mL", "12 ul/ml","16 ul/mL"))
Now this Primary variable has been ordered and can be used in the graph.
library (lattice)
barchart(cd8$Primary~ cd8$`1:100 dilution`+cd8$`1:200 dilution`,labels=T,draw.labels=T,
scales=list(x=list(rot=90,cex=0.8)),xlab="No of CD8 Cells")
Now this plot makes more sense. There are fewer CD8 cells being detected when there is no antibody and the number o CD8 cells detected increased once we add more antibody.