Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

regression line on a ggplot is not shown

$
0
0

When I try to use ggplot, the plot just shows data in dots, but there is no line at all in the plot. Also, There is no error in R. Data has two coloumns, namely Month and Rainfall. I made dataset as follow for several years:

Month Rainfall
1        0.7
2         0
3         0
.         .
.         .
12         1.2
1         0
2         0.2
.         .
.         .

The code for ggplot is below :

  ggplot() + 
   geom_point(aes(x = test_set$Month, y = test_set$Rainfall),
               color = 'red') +
   geom_line(aes(x = training_set$Month, y = predict(regressor, newdata = training_set)),
               color = 'blue') +
   ggtitle('Monthly Rainfall (Test set)') +
   xlab('Month') +
   ylab('Rainfall')

But, I cannot plot a line as simple linear regression.


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>