Plot the mean in the R [closed]

2

How can I plot the average using R Studio and can display the same with my dataset also presented in dimensional space? The mean is represented by this line and the data represented by dots. The code you are using is just for averaging .. wanted it to appear in the illustration

dados <- dbGetQuery(con, "select departure_hour, travel_segment_time from bartolomeumitre; dados.frame <- data.frame(dados); plot(dados.frame); xl <- with(dados.frame, travel_segment_time); mean(xl)

    
asked by anonymous 23.11.2016 / 14:34

1 answer

3

With ggplot2 , you can do this:

library(dplyr)
library(ggplot2)
df <- data_frame(x = rnorm(100), y = x + rnorm(100))

ggplot(df, aes(x = x,  y = y)) + 
  geom_point() +
  geom_hline(aes(yintercept = mean(y))) +
  geom_vline(aes(xintercept = mean(x)))

In your case, this should work:

ggplot(dados.frame, aes(y = travel_segment_time, x = departure_hour)) +          
  geom_point() + 
  geom_hline(aes(yintercept = mean(travel_segment_time))) 
    
23.11.2016 / 18:48