官术网_书友最值得收藏!

Studying the Relationship between Two Numeric Variables

To understand how we can study the relationship between two numeric variables, we can leverage scatter plots. It is a 2-dimensional visualization of the data, where each variable is plotted on an axis along its length. Relationships between the variables are easily identified by studying the trend across the visualization. Let's take a look at an example in the following exercise.

Exercise 30: Studying the Relationship between Employee Variance Rate and Number of Employees

Let's study the relationship between employee variance rate and the number of employees. Ideally, the number of employees should increase as the variation rate increases.

Perform the following steps to complete the exercise:

  1. First, import the ggplot2 package using the following command:

    library(ggplot2)

  2. Create a DataFrame object, df, and use the bank-additional-full.csv file using the following command:

    df <- read.csv("/Chapter 2/Data/bank-additional/bank-additional-full.csv",sep=';')

  3. Now, plot the scatter plot using the following command:

    ggplot(data=df,aes(x=emp.var.rate,y=nr.employed)) + geom_point(size=4) +

    ggtitle("Scatterplot of Employment variation rate v/s Number of Employees")

    The output is as follows:

Figure 2.15: Scatterplot of employment variation versus the number of employees

We use the same base function, ggplot, with a new wrapper for the scatterplot. The geom_point function in ggplot provides the necessary constructs for using a scatterplot.

We can see an overall increasing trend, that is, as employment variance rate increases, we see the number of employees also increases. The fewer number of dots are due to repetitive records in nr.employed.

主站蜘蛛池模板: 正阳县| 锦屏县| 五原县| 隆德县| 新疆| 广州市| 石嘴山市| 卢湾区| 太康县| 蒙山县| 长寿区| 越西县| 子洲县| 九龙县| 周宁县| 六安市| 栖霞市| 栖霞市| 泰和县| 阳高县| 山阳县| 万宁市| 宜城市| 当涂县| 香河县| 双柏县| 始兴县| 安泽县| 邵阳市| 祁门县| 龙里县| 黑龙江省| 海晏县| 通榆县| 丽江市| 林州市| 措美县| 宁海县| 桓仁| 县级市| 汉沽区|