Data Visualization with R codes: Barplots and Scatter plots
Read the earlier article to understand the data by clicking on the link below
Barplot
barplot(table(dataset$age))
# dataput to the command must be vector or matrix
# If you want a horizontal barplot
barplot(table(dataset$age), horiz = TRUE)
# Let us give give title to the barplot
barplot(table(dataset$age),
horiz = FALSE,
main = "age" )
# Let us give axes names
barplot(table(dataset$age),
horiz = FALSE,
main = "age",
xlab = "age",
ylab = "count")
# Let us color to the plot
barplot(table(dataset$age),
horiz = FALSE,
main = "age",
xlab = "age",
ylab = "count",
col = "Blue",
border = "green",
)
## let us add space between the bars
# the amount of space (as a fraction of the average bar width) left before each bar.
barplot(table(dataset$age),
horiz = FALSE,
main = "age",
xlab = "age",
ylab = "count",
col = "Blue",
space = 5)
# Adding limits to X-Axis and y-Axis
# Let us give axes names
barplot(table(dataset$age),
horiz = FALSE,
main = "age",
xlab = "age",
ylab = "count",
col = "Blue",
border = "green",
xlim = c(0, 87),
ylim = c(0, 300))
barplot(table(dataset$age) ,
horiz = FALSE,
main = "age",
xlab = "age",
ylab = "count",
col = "Blue",
border = "green",
xlim = c(0, 87),
ylim = c(0, 300))
Scatter Plot
##Scatter plot - to understand how does one variable change with another variable
# Scatter plots help in visualizing data easily and for simple data inspection.
#Multivariate Scatter Plot
plot(dataset$duration~dataset$y)
# Let us label to the x axias and y axis
plot(dataset$duration~dataset$y, ylab = "duration", xlab = "y")
# Let us add title to the plot
plot(dataset$duration~dataset$y, ylab = "duration", xlab = "y", main = "duration vs y")
# Let us add color to the plot
plot(dataset$duration~dataset$y,
ylab = "duration",
xlab = "y",
main = "duration vs y",
col = "blue")
# Let us add the shape of the plot
# this will give me a solid circle
plot(dataset$duration~dataset$y,
ylab = "duration",
xlab = "y",
main = "duration vs y",
col = "blue",
pch = 16)
plot(dataset$balance~dataset$age)
plot(dataset$duration~dataset$campaign)