InterviewSolution
| 1. |
library(ggplot2) |
|
Answer» Response: The answer is Option A. Yes, trend lines can be ADDED into the plot in R. Below is an example where we have added a vertical line as the mean of the variable for determining the threshold into the histogram plot that we have plotted using the iris DATASET in R. The ggplot2 library in R is leveraged for this purpose. library(ggplot2) GGPLOT(data = iris,aes(x=Sepal.Length))+geom_histogram(fill="lightblue",col="blue")+geom_vline(xintercept = mean(iris$Sepal.Length),color="red",linetype="longdash") The function geom_vline where the line stands for the vertical line is used. Here we just need to provide the intercept on x-axis only. The mean of Sepal.Length parameter is taken as a threshold to determine where the line has to be drawn. The TYPE of the line can also be determined as shown by using the parameter “linetype”. |
|