In: Computer Science
Let x3 be the following vector: x3 <- c(0, 1, 1, 2, 2, 2, 3, 3, 4) Imagine what a histogram of x3 would look like. Assume that the histogram has a bin width of 1. How many bars will the histogram have? Where will they appear? How high will each be? When you are done, plot a histogram of x3 with bin width = 1, and see if you are right.
I need code help R programming
Given:
Bin width is 1
Input Data is given x3 <- c(0, 1, 1, 2, 2, 2, 3, 3, 4)
Solution:
There will be 4 bars in the histogram.
Data will be segregated in different bins in the following way.
1st will have these values: 0,1,1
2nd will have these values: 2,2,2
3rd will have the following values: 3,3
4th will have this value: 4
Bin | Freq |
1st | 3 |
2nd | 3 |
3rd | 2 |
4th | 1 |
R code:
##set working directory where you want to
##save the image file
##setwd()
# Create data for the graph.
x3 <- c(0, 1, 1, 2, 2, 2, 3, 3, 4)
# Give the chart a name##
png(file = "x3_histogram.png")
# Create the histogram.
## Give x axis and y axis a name##
##Give colors to column and border##
## Put limits on x axis and y axis##
## Provide width to each bar using breaks##
hist(x3,xlab = "Weight",col = "blue",border = "red", xlim =
c(0,5), ylim = c(0,5),
breaks=5)
# Save the file.
dev.off()
###Output##