In: Statistics and Probability
Coding in R
Im trying to plot a histogram in R, and i know the basic code for that, however, the code requires 2 plots coming from the same data set. for example, the voltage of an old process vs. a new process. is there any ways to seperate the 2 processes out from the data set to make 2 relative frequencyt histograms?
The best way I know of solving the problem is using the 'ggplot2' package in R.
'ggplot2' is considered as a fine tool to make plots, as you can easily add new features to your plots, and reading and understanding them is easy.
If you have never used ggplot2 before you will have to run the following commands to be able to use it on your system:
install.packages("ggplot2")
library(ggplot2)
Assuming that you have a variable which can separate old processes from the new processes, you can use the following code to make 2 relative frequency histograms from the same data set.
(If you do not have a variable which tells if it is a new process or an old process, you can create the variable.)
NOTE: In the following code, the piece of code in bold is where you have to enter your code.
ggplot(input1,
aes(input2, group = input3 ))
+
geom_histogram(aes(y = ..prop..),position="identity", stat="count")
+
scale_y_continuous(labels=scales::percent) +
ylab("Relative Frequencies") +
facet_grid(~input3 ) +
labs(title="Input2 by input3 (Relative
Frequencies)" )
Input1: Name of the dataset
Input2: 'x' variable
Input3: The variable which separates old processes from new processes. (This must be a factor or a character type variable)
I hope I have understood your question and have answered your question. If there is anything else you might want me to add, please let me know in the comments section and I will do it.