Reputation: 17
I have the following equation that I would like to graphy for y
values between 0 - 20. However I am not sure how to set the data up to use the function plot (x,y)
.
I first defined my y
values as:
y <- data.frame(x = c(1:20))
And then my x
values as:
x<- (exp (-1.973 + 0.598*y) )/ (1+ exp (-1.973+ 0.598*y))
I get back this error when using plot(x,y)
Erreur dans stripchart.default(x1, ...) : méthode graphique incorrecte (error in stripchart: method graphic incorrect)
any tips?
Upvotes: 0
Views: 1764
Reputation: 6396
You could simply create a data.frame object with y and x value, and afterwards plot it.
y <- c(1:20)
x <- exp (-1.973 + 0.598*y) / 1+ exp (-1.973+ 0.598*y)
df <- data.frame(y = y, x = x)
plot(df$y, df$x)
Upvotes: 1
Reputation: 18749
If you want to draw the equation exp(-1.973+0.598*x)/(1+exp(-1.973+0.598*x))
on the range [0,20], the simplest is to use function curve
, this way you don't have to define a y or an x vector since it takes an expression directly:
curve(exp(-1.973+0.598*x)/(1+exp(-1.973+0.598*x)),from=0,to=20)
Upvotes: 1
Reputation: 81683
Since both x
and y
are data frames, you have to extract the first column with [[
before plotting.
plot(x[[1]], y[[1]])
Upvotes: 0