# set the margin, c(bottom, left, top, right)
par(mar = c(3, 4, 3, 4))
# Make the main plot
plot(crops$ph, crops$rainfall, # set x and y
pch = 20, col = 'blue', # set points style
main = 'Relationship between ph, rainfall and humidity', # add main
col.main = 'brown', # set main color
xlab = 'ph', ylab = 'Rainfall') # set x and y axis
# Add a fit line
abline(lm(crops$rainfall ~ crops$ph),
lty = 3, lwd = 3, col = 'blue')
# THE TRICK: Add another scatterplot using points
## Reset plot window
plot.window(xlim = range(crops$ph),
ylim = range(crops$humidity))
## Another syntax to use plot: with(dataset, plot(x, y))
with(crops, points(ph, humidity,
pch = 18, col = 'orange'))
# Add fit line
with(crops, abline(lm(humidity ~ ph),
lty = 4, lwd = 2,
col = 'orange'))
# Add another axis
axis(4, col.axis = "orange")
## Add lab for this axis
mtext(side = 4, line = 2, "Humidity", col = 'orange')
# Add legend
legend("topright", pch = c(20, 18),
col = c("blue", "orange"),
legend = c("Rainfall", "Humidity"))