Given data as follows.
#Read or open data "data R 1.csv"
data=read.csv("data R 1.csv")
#Show the data
data
## Job Income Expenditure
## 1 Lecture 1.0 0.5
## 2 Lecture 1.5 0.9
## 3 Lecture 1.2 0.8
## 4 Lecture 2.5 1.8
## 5 Lecture 3.0 2.1
## 6 Lecture 4.0 1.9
## 7 Lecture 1.9 1.5
## 8 Lecture 2.9 0.8
## 9 Lecture 4.0 3.4
## 10 Lecture 4.5 3.0
## 11 Lecture 4.8 3.2
## 12 Lecture 3.1 2.6
## 13 Lecture 4.3 2.9
## 14 Lecture 4.6 3.8
## 15 Lecture 3.8 3.2
## 16 Lecture 3.2 3.0
## 17 Lecture 2.7 2.2
## 18 Lecture 4.5 2.8
## 19 Lecture 4.4 1.9
## 20 Lecture 4.0 3.0
## 21 Manager 3.6 3.4
## 22 Manager 3.9 3.5
## 23 Manager 4.0 3.9
## 24 Manager 4.5 4.2
## 25 Manager 3.8 3.0
## 26 Manager 5.0 4.0
## 27 Manager 6.7 6.2
## 28 Manager 7.0 6.0
## 29 Manager 6.0 5.5
## 30 Manager 5.6 4.9
## 31 Manager 7.0 6.5
## 32 Manager 8.0 6.6
## 33 Manager 9.0 7.0
## 34 Manager 4.9 3.9
## 35 Manager 5.2 5.0
## 36 Manager 5.7 5.1
## 37 Manager 5.4 5.1
## 38 Manager 7.2 6.2
## 39 Manager 4.6 4.0
## 40 Manager 6.7 6.1
Based on data above, there are three variables, namely:
plot(data[2:3]) #Plot data with income as horizontal axis, and expenditure as vertical axis. Income in the second column [2] & expenditure in the third column [3].
plot(data[2:3], main="Income and Expenditure")
Income=data$Income
Expenditure=data$Expenditure
plot(Income, Expenditure)
library(ggplot2)
qplot(data$Income, data$Expenditure)
library(ggplot2)
Income=data$Income
Expenditure=data$Expenditure
qplot(Income, Expenditure)
#XLAB, YLAB, MAIN
library(ggplot2)
Income=data$Income
Expenditure=data$Expenditure
qplot(Income, Expenditure, main="The Rate of Income & Expenditure Per-Month", xlab="Income Per-Month", ylab="Expenditure Per-Month")
#COLOR
library(ggplot2)
Income=data$Income
Expenditure=data$Expenditure
Job=data$Job
qplot(Income, Expenditure, main="The Rate of Income & Expenditure Per-Month", xlab="Income Per-Month", ylab="Expenditure Per-Month", color=Job)
#SHAPE
library(ggplot2)
Income=data$Income
Expenditure=data$Expenditure
Job=data$Job
qplot(Income, Expenditure, main="The Rate of Income & Expenditure Per-Month", xlab="Income Per-Month", ylab="Expenditure Per-Month", color=Job, shape=Job)
#GGPLOT
library(ggplot2)
ggplot(data, aes(Income, Expenditure)) + geom_point()
#GGPLOT
library(ggplot2)
ggplot(data, aes(Income, Expenditure)) + geom_point(aes(color = Job,
shape = Job))
#GGPLOT
library(ggplot2)
save <- ggplot(data, aes(Income, Expenditure)) + geom_point(aes(color = Job,
shape = Job))
save + scale_colour_manual(values = c("blue", "orange"))
save + scale_shape_manual(values = c(16, 5))
save + scale_colour_manual(values = c("blue", "orange")) + scale_shape_manual(values = c(5, 5))
save + scale_colour_manual(values = c("blue", "orange")) + geom_text(data = NULL, x = 3.5, y = 6, label = "Income & Expenditure Per-Month", colour="red")
save + facet_grid(. ~ Job)
save + facet_grid(. ~ Job) + scale_colour_manual(values = c("blue", "orange"))
save + geom_vline(xintercept = 2.5)
save + geom_vline(xintercept = 2.5) + geom_vline(xintercept = 5)
save + geom_vline(xintercept = 1:5)
save + geom_vline(xintercept = c(2.5, 5, 7.5))
save + geom_vline(xintercept = c(2.5, 5, 7.5), colour="green", linetype = "longdash")
save + geom_vline(xintercept = c(2.5, 5, 7.5), colour="green", linetype = "longdash") + geom_hline(yintercept = c(2, 4, 6), colour="red", linetype = "longdash")