(s) Phoebe Martin
2022-Feb-11 15:24 UTC
[R] Animated Face plot in R (Moving golf club face)
Hi, I am wanting to create an animated 3d plot that mimics a golf club face in a swing. The data I have is fiducials (marker point coordinates) through various time stamps. So far, I have been able to create one 3d plot using mesh3d of the club face in one moment in time. However here I would like to make many of these plots at the different time stamps (see image 2 for coordinates) and create an animation of this face moving. Image 1 shows the output of the current graph, which can rotate and hover over markers to show their labels i.e. Heel. [Current plot outcome][1]: https://i.stack.imgur.com/Ne3Po.png Image 2 is the coordinates of the required plots (to make a moving graph). [Coordinates that I want multiple plots for, to create moving animation] https://i.stack.imgur.com/srEdW.png Below is the example code where I have inputted the x, y & z data very simply as an example of what I am wanting to achieve. Any help would be greatly appreciated, thank you. Please let me know if you need any more information from me! library(rgl) library(tidyverse) library(plotly) df <- data.frame(x=c('-278.76', '-302.2','-283.57','-275.18','-281.165'), y=c('52.66','-4.39','-3.84','-3.29','24.41'), z=c('40.87','63.68','36.95','24.25','38.91')) # Create a table of coordinates marker<-c("Heel","TToe","MToe","BToe","Centre") rownames(df)<-marker # Label row names #head(df) #display table x <- as.numeric(df$x) # Assigning elements of dataframe to x, y & z y <- as.numeric(df$y) z <- as.numeric(df$z) ##PLANE/SURFACE PLOT plot_ly(x=~x, y=~y, z=~z, type='mesh3d', text = ~paste('Marker:', marker), hoverinfo='text') # Enables hover to identify marker points and rotation [[alternative HTML version deleted]]
Please note, per the posting guide linked below: "For questions about functions in standard packages distributed with R (see the FAQ Add-on packages in R), ask questions on R-help. [The link is: https://cran.r-project.org/doc/FAQ/R-FAQ.html#Add-on-packages-in-R This gives the list of current _standard_ packages] If the question relates to a contributed package , e.g., one downloaded from CRAN, try contacting the package maintainer first. You can also use find("functionname") and packageDescription("packagename") to find this information. Only send such questions to R-help or R-devel if you get no reply or need further assistance. This applies to both requests for help and to bug reports." In particular, plotly is NOT an R package and is a product of a for-profit software company who you should contact for your query: either here: https://plotly.com/r/getting-started/ or here: https://community.plotly.com/c/graphing-libraries/5 (I think) Cheers, Bert On Fri, Feb 11, 2022 at 8:41 PM (s) Phoebe Martin < P.Martin-19 at student.lboro.ac.uk> wrote:> Hi, > > I am wanting to create an animated 3d plot that mimics a golf club face in > a swing. The data I have is fiducials (marker point coordinates) through > various time stamps. So far, I have been able to create one 3d plot using > mesh3d of the club face in one moment in time. However here I would like to > make many of these plots at the different time stamps (see image 2 for > coordinates) and create an animation of this face moving. > > Image 1 shows the output of the current graph, which can rotate and hover > over markers to show their labels i.e. Heel. [Current plot outcome][1]: > https://i.stack.imgur.com/Ne3Po.png > > Image 2 is the coordinates of the required plots (to make a moving graph). > [Coordinates that I want multiple plots for, to create moving animation] > https://i.stack.imgur.com/srEdW.png > > Below is the example code where I have inputted the x, y & z data very > simply as an example of what I am wanting to achieve. > > Any help would be greatly appreciated, thank you. Please let me know if > you need any more information from me! > library(rgl) > library(tidyverse) > library(plotly) > > df <- data.frame(x=c('-278.76', > '-302.2','-283.57','-275.18','-281.165'), > y=c('52.66','-4.39','-3.84','-3.29','24.41'), > z=c('40.87','63.68','36.95','24.25','38.91')) # > Create a table of coordinates > marker<-c("Heel","TToe","MToe","BToe","Centre") > rownames(df)<-marker # Label row names > #head(df) #display table > x <- as.numeric(df$x) # Assigning elements of dataframe to x, y & z > y <- as.numeric(df$y) > z <- as.numeric(df$z) > > ##PLANE/SURFACE PLOT > plot_ly(x=~x, y=~y, z=~z, type='mesh3d', text = ~paste('Marker:', > marker), > hoverinfo='text') # Enables hover to identify marker points > and rotation > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]