How to create a bar chart using a lattice package in R? Bar charts are a graphical representation of categorical or discrete type of data. The data is represented in the form of rectangular bars either horizontally or vertically on the graph. Bar graphs can be used to compare different categories of data over a time period. Lattice is a data visualization and graphics package in R — graph_type (formula, data) This recipe demonstrates an example on a bar chart.
data <- data.frame(x = c(10,5,6,15,20,19), type = c("A","B","C","D","E","F")) print(data)"Data is :" print(data) x type 1 10 A 2 5 B 3 6 C 4 15 D 5 20 E 6 19 F
syntax - barchart(x,data,main,xlab,ylab) x - the categorical data value data - the input data main - the title of the chart xlab - the title of the x axis ylab - the title of the y axis
barchart(x~type, data=data, main="Bar chart", xlab="x_values", ylab="type")
" Output of the code is :"