2016-04-04 23 views
2

私はcsvファイルからデータを読み込むスクリプトを持っています。私は平均を計算していますが、私は水平線としてグラフ上の平均を見たいと思います。平均の水平線数がggplot2のR

avg = myData$Electricity.Costs 
mean(avg) 

ggplot(data = myData, 
     aes(x = Date, y = Electricity.Costs, 
      group = Budget.Plan.Monthly.Amount, colours = "Budget.Plan.Monthly.Amount")) + 
    geom_line() + 
    geom_point(aes(colour = Budget.Plan.Monthly.Amount)) 

お願いします。

答えて

3
ggplot(data = myData, 
    aes(x = Date, y = Electricity.Costs, 
     group = Budget.Plan.Monthly.Amount, colours = "Budget.Plan.Monthly.Amount")) + 
geom_line() + 
geom_point(aes(colour = Budget.Plan.Monthly.Amount))+ 
geom_hline(yintercept = mean(avg)) 
+0

ありがとう、私はyintercept = avgをyintercept = mean(平均)に変更する必要があります。今すぐうまくいく:) – Karol