InterviewSolution
Saved Bookmarks
| 1. |
When will you use a histogram and when will you use a bar chart in R? Explain with an example by leveraging R package. |
|
Answer» We use a histogram to plot the distribution of a continuous VARIABLE, while we can use a bar CHART to plot the distribution of a categorical variable. Let us take the example of IRIS dataset in R. We will plot a histogram of IRIS dataset with leveraging “ggplot2” package in R. “Sepal.Length” is a continuous variable which is PLOTTED below onto the x-axis. Code: ggplot(data = iris,aes(x=Sepal.Length))+geom_histogram(fill="lightblue",col="blue")We will plot a bar chart of IRIS dataset with leveraging “ggplot2” package in R. “Species” is a categorical variable which is plotted below onto the x-axis. Code: ggplot(data = iris,aes(x=Species))+geom_bar(fill="SKYBLUE") |
|