I am new to piping and dplyr in R and need some help. Please note- I have a solution for this question using cut function.
Plotting Categorical Values Histogram in R
I want to solve the problem using dplyr. I want to use dplyr to create a frequency table (do not want to store this frequency table) and plot the data using ggplot.
Problem: I have data from 2 sensors- reference data and sensor data (this is the sensor I am evaluating). Sensor data is categorical data (1 or 2 or 3). I am trying to plot a histogram of status of sensor for different bin values of reference. For example: when the reference value is 1-5, I want to see a frequency distribution of sensor 1 status (1 or 2 or 3). Similarly for 6-10 of reference data and upto 95-100 of reference value, I want a frequency distributions of sensor status. Please see sample data below. Appreciate the help.
dput(sample1)
structure(list(test_data = c(1.2, 0.2, 0.6, 1.6, 1, 1, 0.4,
0.4, 0.8, 0.8, 0.4, 0.2, 15.8, 59.2, 55.4, 54.8, 54.6, 54.2,
49, 53, 47.2, 44, 40.2, 39, 34.2, 35.8, 33.4, 30.6, 29.4, 29.2,
27.6, 24.8, 24, 22, 21.2, 20.6, 18.6, 18, 17, 17.2, 14.8, 15.2,
13.2, 13.4, 12, 11.8, 11, 10.8, 10, 9.2, 8.8, 8.8, 8.4, 7.8,
7.6, 6.6, 6.4, 6.2, 6, 5.8, 5.4, 5, 4.8, 4.4, 4.2, 4, 3.8, 3.6,
3.6, 3.6, 3, 2.8, 3, 2.8, 2.6, 2.4, 2.4, 2.2, 2, 2.2, 2.2, 1.8,
1.8, 1.6, 1.8, 1.8, 2.2, 71.2, 75.8, 74.6, 74.6, 74.2, 67.2,
66.2, 60.6, 60.6, 54.8, 53.6, 48.4, 45.2), status = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)), row.names = 113:212, class = "data.frame")