Why does the following code successfully add a nice lowess smooth through these data points? When the span is at 0.5, warning are generated that say
all data on boundary of neighborhood. make span bigger
But even setting the span at 1, you don't get a span, but some of the data points are connected with lines.
This question suggests it is because the x-axis data has multiple entries for some points, and that does happen here. It suggests adding some jitter to the data. I did that with geom_jitter()
(not included in code below) but that didn't solve the problem. I also tried using a sequence of numbers as the x-axis values, instead of the date and that did not work either.
Reproducible code follows below.
Thank you for any insights.
myfile<-'https://raw.githubusercontent.com/sjkiss/NDP/master/Data/membership_data_NDP.csv'
members<-read.csv(myfile, colClasses=c('Date', 'numeric','numeric', 'numeric', 'numeric', 'numeric','numeric', 'Date', 'character'))
theme_set(theme_bw())
members %>%
select(population, votes_previous_election, seats_previous_election, members, date, recent_election) %>%
mutate(., members_per_capita=members/population, members_votes=members/votes_previous_election, members_seats=members/seats_previous_election) %>%
rename(., `Members\nper_capita`=members_per_capita, `Members\nper_vote`=members_votes, `Members\nper_seat`=members_seats) %>%
gather(Variable, Value, 7:9) %>%
ggplot(., aes(x=date, y=Value, group=recent_election))+geom_point(aes(col=factor(recent_election)))+scale_color_discrete(name = "Recent Election")+scale_x_date() +facet_wrap(~Variable, scales='free')+geom_smooth(method='loess', span=0.5)
warnings()```