How to connect specific attributes over polar coordinates in R? -


i have highlighted specific activities (feeding,resting , sleeping) dataset in plot. want connect these highlighted points in sequence on polar coordinates.

here's dataset:

activity  latitude  longitude feeding   21.09542  71.06014 resting   21.09564  71.06064 sleeping  21.09619  71.06128 walking   21.09636  71.06242 walking   21.09667  71.06564 resting   21.09483  71.06619 

can me out in this?

ok starting scratch: original answerwas bulky , inflexible.

just add following paths each activity without filtering.

+ geom_path(aes(colour=activity,x=latitude,y=longitude)) 

enter image description here

if want plot selected activities:

+ geom_path(data=data[data$activity %in% c("sleeping","resting"),],aes(colour=activity,x=latitude,y=longitude)) 

enter image description here

the selected activities listed in c(...) vector each name quoted.

update: op clarified wants connect stationary point, achieved running following:

+ geom_path(data=data[data$activity!="walking",],colour="red",aes(x=latitude,y=longitude)) 

note colour=activity removed aesthetics , consider stationary points (!="walking") draw path.

code combining 2 answers:

set.seed(1) mydf=data.frame(activity=sample(c("walking","walking","walking","walking","walking","resting","feeding","sleeping"),20,t),latitude=rnorm(20,21,0.5),longitude=rnorm(20,71,0.5)) mydf$order=1:nrow(mydf)  # plot library(ggplot2) ggplot(data=mydf)+ geom_point(aes(x=latitude,y=longitude,colour=activity),size=5)+ geom_path(aes(x=latitude,y=longitude),size=1.2)+ geom_text(aes(x=latitude,y=longitude,label=order))+ geom_path(data=mydf[mydf$activity!="walking",],colour="red",aes(x=latitude,y=longitude)) + coord_polar(theta="y") 

enter image description here


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -