We can generate a lowess
line on top of the Scatter diagram. The lowess
line would likely show a better fit as smoothing is used to fit the line to the data.
We can use the same Scatter diagram as the basis and then call upon lines
to add our lowess
line:
# load the iris dataset data <- read.csv("http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data") #Let us also clean up the data so as to be more readable colnames(data) <- c("sepal_length", "sepal_width", "petal_length", "petal_width", "species") # call plot first plot(data$sepal_length, data$petal_length) # add the lowess line to the graph lines(lowess(data$sepal_length, data$petal_length), col="blue")
Here is the resulting graph: