Last active
May 18, 2016 06:28
-
-
Save dragstar328/0accd7b10d6633d8e41285bce10e1aa2 to your computer and use it in GitHub Desktop.
気温の近似曲線を描く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
kion = read.csv("kion_20160501.csv", header = T, colClasses = c("POSIXct", "numeric")) | |
head(kion) | |
summary(kion) | |
g = ggplot(kion, aes(1:nrow(kion), temp)) + geom_line(colour="blue") + labs(title="2016/05/01") | |
plot(g) | |
x = 1:nrow(kion) | |
y = kion[,2] | |
kinji = nls(y ~ a * x^3 + b * x^2 + c * x + d, start=c(a=0, b=0, c=0, d=0)) | |
summary(kinji) | |
predict.c = predict(kinji) | |
kd = data.frame(predict.c) | |
kd$num = 1:nrow(kion) | |
coef = coefficients(kinji) | |
coef[1] | |
coef[2] | |
coef[3] | |
coef[4] | |
k = geom_line(aes(kd$num, kd$predict.c), colour="red") | |
a = annotate("text", label= "y = -0.009 * x^3 + 0.285 * x^2 -1.64 * x + 14.62", x=7, y=25, col="red") | |
plot(g + k + a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment