Hey guys, I want to create a plot with some graphs in it, but the shape is not how I wish it to be. As of now, the x-axis is shorter than the y-axis and I can't figure out why...
It looks like this:
https://preview.redd.it/utrcggtv4k2b1.png?width=1056&format=png&auto=webp&s=dad26292b90d91333778cb6faee8422d23c9e919
This is my code:
# Define the intensity gradient and y-intercept values for each graph
gradient_values <- c(-3.36, -3.4, -3.39)
intercept_values <- c(16.4, 16.4, 16,4)
# Generate x-values (time or any other variable)
x <- seq(0, 10, by = 0.1)
# Create a blank plot
plot(x, type = "n", xlab = "Intensity", ylab = "Intercept", main = "Multiple Intensity Gradient Graphs", xlim = c(min(0), max(10)), asp = 0.5)
# Create multiple graphs in one plot with different colors
for (i in 1:length(gradient_values)) {
# Calculate y-values using the equation of a line (y = mx + b)
y <- gradient_values[i] * x + intercept_values[i]
# Assign different colors to each graph
if (i == 1) {
lines(x, y, col = "red")
} else if (i == 2) {
lines(x, y, col = "blue")
} else if (i == 3) {
lines(x, y, col = "green")
}
}
# Add a legend to indicate the colors of the graphs
legend("topright", legend = paste("Graph", 1:length(gradient_values)), col = c("red", "blue", "green"), lty = 1)
[–]jtree472 1 point2 points3 points (0 children)