2017-08-21 193 views
-1

我一直在试图为我的ggplot添加一个趋势线(关于发送的电子邮件活动&的相应打开率)。使用ggplot绘制趋势线R

我首先将x轴转换为时间序列数据,而y轴是打开率(%),然后我将ggplot绘制为正常。下面是我的代码:

x= strptime(service_equity$`Send Date`, '%d/%m/%Y') 
y = service_equity$`Open Rate` 
ggplot(service_equity, aes(x,y)) + geom_point() + geom_smooth(method= "lm") ggtitle("Trend in Open Rate") 

在剧情中使用的数据:

> x[1] "2015-02-24 GMT" "2014-09-16 BST" "2015-10-26 GMT" "2016-10-27 BST" "2017-01-19 GMT" "2015-06-25 BST" "2017-03-14 GMT" "2017-04-27 BST" 

> y[1] "23.15%" "26.62%" "26.93%" "22.94%" "25.26%" "23.85%" "19.59%" "17.14%" "27.68%" "26.56%" "24.14%" "26.36%" "22.32%" "34.63%" "34.60%" 

散点图已成功绘制,但趋势线是不存在的,并且没有错误消息或通知关于“geom_smooth”功能。

enter image description here

请帮帮忙!

+1

你见过这些贴子的[1](https://stackoverflow.com/questions/38412817/draw-a-trend-line-using-ggplot),[2](https://stackoverflow.com/questions/11476849/creating-ggplot-stack-bar-and-trend-line),[3](https://stackoverflow.com/questions/10911057/adding-a-simple-lm-trend-line-toa-a- ggplot-箱线/ 10911838#10911838),[4](https://stackoverflow.com/questions/12810861/how-to-get-a-single-trendline-with-multiple-data-sets-in-r-and -ggplot2)和[5](https://stackoverflow.com/search?q=trendline+ggplot2)。如果是,并且您还没有找到解决方案,请描述您的问题是如何区别的? – Ashish

+0

,因为您的y轴被视为一个因素,由于[%]符号 –

回答

1

geom_smooth()不因性因素列工作- >你的Y轴是因为[%]标志的一个因素,是geom_smooth()工作,你需要有数字数据!

摆脱[%]号和geom_smooth()应该工作。