r - Error in prettyDate range too small for min.n in ggplot2 facet chart -
i have dataset olympics results in athletics. need make facet ggplot different categories, example 100m , marathon subset:
ath.sub <- subset(ath, event_std%in%c('100m','marathon'))
i got dataframe
> head(ath.sub) event event_std athlete country result medal year unit sex time 1261 100m men 100m usain bolt jam 9.69 gold 2008 time men 2011-01-01 1262 100m men 100m donovan bailey can 9.84 gold 1996 time men 2011-01-01 1263 100m men 100m justin gatlin usa 9.85 gold 2004 time men 2011-01-01 1264 100m men 100m francis obikwelu por 9.86 silver 2004 time men 2011-01-01 1265 100m men 100m maurice greene usa 9.87 gold 2000 time men 2011-01-01 1266 100m men 100m maurice greene usa 9.87 bronze 2004 time men 2011-01-01 > tail(ath.sub) event event_std athlete country result medal year unit sex time 3370 marathon women marathon valentina yegorova rus 2:28.05 silver 1996 time women 2011-01-01 02:28:00 3371 marathon women marathon yuko arimori jpn 2:28.39 bronze 1996 time women 2011-01-01 02:28:00 3372 marathon women marathon valentina yegorova urs 2:32:41 gold 1992 time women 2011-01-01 02:32:00 3373 marathon women marathon yuko arimori jpn 2:32:49 silver 1992 time women 2011-01-01 02:32:00 3374 marathon women marathon lorraine moller nzl 2:33.59 bronze 1992 time women 2011-01-01 02:33:00 3375 marathon women marathon catherine ndereba ken <na> silver 2008 time women <na> > str(ath.sub) 'data.frame': 236 obs. of 10 variables: $ event : chr "100m men" "100m men" "100m men" "100m men" ... $ event_std: chr "100m" "100m" "100m" "100m" ... $ athlete : chr "usain bolt" "donovan bailey" "justin gatlin" "francis obikwelu" ... $ country : chr "jam" "can" "usa" "por" ... $ result : chr "9.69" "9.84" "9.85" "9.86" ... $ medal : chr "gold" "gold" "gold" "silver" ... $ year : int 2008 1996 2004 2004 2000 2004 1996 2008 1996 2008 ... $ unit : chr "time" "time" "time" "time" ... $ sex : chr "men" "men" "men" "men" ... $ time : chr "2011-01-01 00:00:09.69" "2011-01-01 00:00:09.84" "2011-01-01 00:00:09.85" "2011-01-01 00:00:09.86" ...
then convert time field in posixct
> ath.sub$time<-as.posixct(ath.sub$time,tz = 'gmt') > str(ath.sub$time) posixct[1:236], format: "2011-01-01 00:00:00" "2011-01-01 00:00:00" "2011-01-01 00:00:00" "2011-01-01 00:00:00" ...
as wrote before need make ggplot facet line chart. if choose similar disciplines (like 100m or 400m) i've no problems. different time discipliens 100m , marathon got error
error in prettydate(x = x, n = n, min.n = min.n, sep = sep, ...) :
range small 'min.n'
here ggplot code
gg.ath<- ggplot(ath.sub, aes( year, time, colour=sex))+ facet_wrap(~event_std, scales = 'free')+ scale_y_datetime()+ scale_x_continuous(breaks = ath.sub$year)+ geom_line()+ geom_smooth()
my colleague fixed it, used lubridate package while converting time field
ath.sub$time <- lubridate::ymd_hms(ath.sub$time)
Comments
Post a Comment