Reputation: 1681
I have not done this in my life, but is it possible to extract any number of points from a given slope/graph with Gnu R? Do be more precise, can I tell Gnu R to give me 400 points alongside the given data (is it not called interpolation even)? Imagine you have the following data:
dput(df1)
structure(list(census = structure(c(-281037, -253644, -244513,
-231730, -228077, -217120, -209815, -207989, -191553, -180596,
-171465, -129462, -98416, -90381, -80154, -71388, -61892, -33768,
4582, 11887, 15540), class = "Date"), pop_hist = c(0, 30, 1000,
2000, 3000, 4100, 3900, 4100, 3900, 4000, 4100, 4000, 4030, 4080,
2000, 1500, 1050, 111, 1936, 3791, 5167)), .Names = c("census",
"pop_hist"), row.names = c(NA, -21L), class = "data.frame")
and the graphical output
Edit:
I have this command from the library(pracma)
:
interp1(x=as.numeric(census),y=as.numeric(pop_hist),xi=as.numeric(census),method="nearest")
But how can I tell R to give me around 400 points?
Upvotes: 2
Views: 121
Reputation: 1681
The answer is, thank you wdkrnls:
library(ggplot2)
test <- approx(x=as.numeric(census),y=as.numeric(pop_hist),n=474,method="linear")
ggplot(test,aes(y=y,x=x)) + geom_line()
Upvotes: 1