plot - plotting a quadratic function in R -


here's how plotted quadratic curve:

factor <- 1:7  data <- c(0.1375000,0.2500000,0.3416667,0.4583333,0.7250000,0.9166667,1.0000000)  plot(factor, fitted(lm(data~factor+i(factor^2))), type="l") 

enter image description here

i try same data.

factor1<-c(2833,2500,2437,2124,1382,3736,2100,1844,2740,957,1614,1100,1550,3858,2430,2139,1812,1757,1847,945)  data1<-c(0.95,0.88,0.88,0.93,0.81,0.67,0.55,0.53,0.52,0.90,0.87,0.20,0.28,-0.16,0.23,0.11,0.26,0.08,0.73,0.76)  plot(factor1,fitted(lm(data1~factor1+i(factor1^2))), type="l") 

enter image description here

i think because second dataset not sorted thought r automatically sorts them before plotting them.

could tell me how plot quadratic line in second plot.

you can order first

i<-order(factor1) plot(factor1[i],fitted(lm(data1[i]~factor1[i]+i(factor1[i]^2))), type="l") 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -