type = "l" is used to create a Line plot.
Used in plot() function.
Instead of points it shows a line.
Syntax plot(x, y, type = "l")
# Create sample data
x <- 1:10
y <- x^2
# Create a line plot
plot(x, y, type = "l", col = "blue", lty = 2, lwd = 2, main = "Line Plot", xlab = "X-axis", ylab = "Y-axis")
There are different types of line styles(lty) based on the values
# Create sample data
x <- 1:10
y <- x^2
# Create a plot with different line types
plot(x, y, type = "n", main = "Line Types", xlab = "X-axis", ylab = "Y-axis")
lines(x, y, col = "blue", lty = 1, lwd = 2) # Solid line
lines(x, y + 10, col = "green", lty = 2, lwd = 2) # Dashed line
lines(x, y + 20, col = "red", lty = 3, lwd = 2) # Dotted line
lines(x, y + 30, col = "purple", lty = 4, lwd = 2) # Dot-dash line
lines(x, y + 40, col = "orange", lty = 5, lwd = 2) # Long-dash line
lines(x, y + 50, col = "brown", lty = 6, lwd = 2) # Two dash-dot line
lines(x, y + 60, col = "pink", lty = 7, lwd = 2) # Dash-dot-dot line
lines() are used to show a line connecting all the points.
This function is mainly used when we dont use type="l" i plot() function.
So that we can show point and connecting lines.
# Create another set of data
x2 <- 1:10
y2 <- 3 * x2 - 1 + rnorm(10)
# Create a new scatter plot
plot(x2, y2, main = "Scatter Plot with Another Line", xlab = "X-axis", ylab = "Y-axis", pch = 16, col = "green")
# Add a line to the existing plot using lines()
lines(x2, y2, col = "orange", lty = 2)
We can use albine() function to show an line for the points.
Mainly used in scatterplot.
Type = "b" plot creates a plot with both points and lines.
The plot will have a data points which will be connected by lines.
Syntax plot(x, y, type = "b")
# Create sample data
x <- 1:10
y <- x^2
# Create a plot with points and lines
plot(x, y, type = "b", col = "blue", pch = 16, lty = 2, lwd = 2, main = "Points and Lines", xlab = "X-axis", ylab = "Y-axis")
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.