etc5523-2020 / exercise2C

For students to submit their reproducible example in the issue
0 stars 0 forks source link

Failed to draw geom_smooth line to know the conditional mean #12

Open Yiwen-Zhang-259 opened 4 years ago

Yiwen-Zhang-259 commented 4 years ago

Hi, I try to use the whole data to draw a point plot as well as a smoothed line to know the conditional mean of this dataset. It works well in the point plot part, but when it came to the smoothed line, I failed. Could anyone help me with this ? Here is my code, thank you ! And excepting for this, I also notice that the x-axis is too congested as others posted previously, which is also the same problem for me.

`library(tidyverse) library(ggplot2)

count_date <- tribble(~Date, ~freq, "13-04-2015", "24", "13-05-2015", "12", "13-06-2015", "32", "14-04-2015", "23", "14-05-2015", "15", "14-06-2015", "16", "15-04-2015", "12", "15-05-2015", "12", "15-06-2015", "34", "16-04-2015", "20", "16-05-2015", "16", "16-06-2015", "29", "17-04-2015", "21", "17-05-2015", "7", "17-06-2015", "32", "18-04-2015", "8", "18-05-2015", "14", "18-06-2015", "47", "19-04-2015", "9", "19-05-2015", "12", "19-06-2015", "29", "20-04-2015", "20", "20-05-2015", "15", "20-06-2015", "16", "21-04-2015", "12", "21-05-2015", "17", "21-06-2015", "12", "22-04-2015", "22", "22-05-2015", "14", "22-06-2015", "30", "23-04-2015", "23", "23-05-2015", "12", "23-06-2015", "190", "24-04-2015", "24", "24-05-2015", "7", "24-06-2015", "218", "25-04-2015", "16", "25-05-2015", "12", "25-06-2015", "98", "26-04-2015", "8", "26-05-2015", "27", "26-06-2015", "55", "27-04-2015", "25", "27-05-2015", "17", "27-06-2015", "39", "28-04-2015", "26", "28-05-2015", "26", "28-06-2015", "27", "29-04-2015", "22", "29-05-2015", "14", "29-06-2015", "51", "30-04-2015", "24", "30-05-2015", "9", "30-06-2015", "53", "31-05-2015", "10", "4/1/2015", "18", "4/10/2015", "21", "4/11/2015", "5", "4/12/2015", "15", "4/2/2015", "27", "4/3/2015", "15", "4/4/2015", "12", "4/5/2015", "6", "4/6/2015", "13", "4/7/2015", "25", "4/8/2015", "28", "4/9/2015", "21", "5/1/2015", "12", "5/10/2015", "7", "5/11/2015", "12", "5/12/2015", "7", "5/2/2015", "7", "5/3/2015", "5", "5/4/2015", "12", "5/5/2015", "14", "5/6/2015", "14", "5/7/2015", "15", "5/8/2015", "15", "5/9/2015", "11", "6/1/2015", "25", "6/10/2015", "25", "6/11/2015", "21", "6/12/2015", "43", "6/2/2015", "25", "6/3/2015", "25", "6/4/2015", "12", "6/5/2015", "29", "6/6/2015", "11", "6/7/2015", "9", "6/8/2015", "24", "6/9/2015", "23")

ggplot(count_date, aes(Date,freq)) + geom_point() + geom_line(aes(group=Date)) + xlab("Date") + ylab("No. of Complaints") + geom_smooth() `

image