簡體   English   中英

R用ggplot2水平線表示平均值

[英]R with ggplot2 horizontal line for average

我的腳本從csv文件中讀取數據。 我正在計算平均值,但我希望將圖上的平均值看作水平線。

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

你能給我一些建議嗎?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM