Reputation: 29
I want to set the starting point of my graph (both in the x- and y-axis) to be zero. I have used the xlim()
and ylim()
functions to no avail. I have attached my code below.
setwd ("D:/Rcode/Assignment_2") #setting up the working directory
LightGrowth1 <- read.csv ("LightGrowth-1.csv") #reading the file and attaching it to a dataframe
Light <- LightGrowth1$light #attach our light values to a vector in R
Growth <- LightGrowth1$growth #attach our growth values to a vector in R
Labels <- c("Light", "Growth") #create a vector using the labels
plot (Light, Growth, xlab = "Amount of Light (units)", ylab = "Plant Growth (units)",
pch = 16, col= "firebrick", xlim = c(0, max (Light)), ylim = c (0, max (Growth)),
main = "Plant Growth vs Amount of Light"
)
This is what my plot currently looks like:
Upvotes: 0
Views: 2425
Reputation: 51640
Your axes do start at 0, and xlim
and ylim
are what you need to change that.
What I think you are referring to is the spacing between the axes and the plot.
There are two extra parameters that allow you to change that, xaxs
and yaxs
.
plot (x, y, xlim=c(0,10), ylim=c(0,10),
xaxs="i", yaxs="i")
This should do the trick
See the par
help for more info.
Upvotes: 1