2016-04-04 9 views
2

Ich habe mein Skript, das Daten aus der CSV-Datei liest. Ich berechne den Durchschnitt, aber ich möchte den Durchschnitt in der Grafik als horizontale Linie sehen.R mit ggplot2 horizontale Linie für den Durchschnitt

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)) 

Könnten Sie mir bitte einen Rat geben?

Antwort

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

Vielen Dank nur ich muss ändern Yintercept = AVG zu Yintercept = Mean (AVG). Funktioniert jetzt gut :) – Karol

Verwandte Themen