Saving sequence tree from GraphViz - r

I'm new to TraMineR and sequence analysis in general. I am working on a project related to retention and recruitment of educational leaders and finding TraMineR to be very useful. This may be a simple thing (and somewhat unimportant), but I cannot seem to figure out how to name or direct the sequence tree created by GraphViz within the TraMinR package. Right now, my code is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showdepth=TRUE)
It produces a great graphic, but with a random file name that I cannot relocate if I accidentally close the graphic.
My main goal is to be able to uniquely name and save these graphs and pull into an R Markdown for the full project. To this point, the only thing I cannot pull in is the seqtree graphic.

Well, guess I figured it out! I didn't realize that the order in which filename command mattered...so...what seems to work out beautifully is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showtree=TRUE,showdepth=TRUE,filename="retaintree.png",imageformat="png")
And to incorporate the file in the Markdown i use the command
```
![](C:\Users\myname\Desktop\retaintree.png)
```{r fig.width=8.5, fig.height=11}
Hope this helps someone else along the way!

Related

Flexdashboards : is the original dataframe used to create tables/graphs secure?

I am very sorry if this is a stupid question,
I was wondering… let’s say you have an HTML file created from R Markdown containing some graph. More specifically, this HTML document is a flexdashboard. Is it possible to obtain the original dataframe used to create the graph, using only this HTML file?
I don’t know if I managed to explain, but I am worried about the security of the original dataframe.
I suppose the real question is, how does Markdown knit the R chunks? Is it only the outcome of the code that is incorporated in the HTML document... or is it everything? I always thought that because knitr create a .md temporary file that contains the code and its outcomes that meant that it only contained the code and the outcomes and not the original dataframe used to make graphs, stats, tables, etc. But I may be completely wrong and I wish to know the truth.
If anybody has the answer (and maybe some tips in how to secure the flexdashboards), I would be very thankful. I hope I managed to explain my problem in a comprehensible way.

How to make a function like swirl() in R?

I was interested in generating a course like "swirl" in R. So a course that would interact with the user upon running it. I wanted to start from scratch and I am not sure on how to do this. Is there any specific documentation for this technique or does it have a specific name I could look for?
Maybe learnr with rmarkdown?
With learnr you can create rmarkdown docs that can run code, show results, preserve code and results.

Repeatable Macros in R?

Is there any way in R to write a macro like one would in SAS? That is, I want to write a macro with some input variable (corresponding to a row in a dataset) so I can quickly make a plot of certain characteristics from said row. Any information regarding a package/method to do so would be greatly appreciated.
R will generate some very, very, very basic code for you. If you have RStudio installed, you can click File > Import Dataset > From ... point to your file and click 'Open'. R will automatically create the code to do the import. Again, this is very basic. You really need to know how to code to do anything useful.
You get out of it what you put into it, so spend some time learning this stuff, and inevitably you'll learn a ton. I've found that it's very helpful to read through people's questions that are posted here, and try to solve the problem yourself. You'll learn a lot that way and you'll see what the current trends are. Reading books is great, of course, but sometimes I feel like some authors are too academic, and in the real world, sometimes it's done differently than what you see in textbooks.

Looking to save a 3D spectrograph generated by SeeWave as .STL or similar in R

I'm fairly new to R and was experimenting with the SeeWave package to generate different plots from audio files. I found the 3D spectrograph especially interesting and, since I have access to a 3D printer in lab, thought it would be neat to print some of them.
My problem isn't with generating the plots, that goes quite smoothly, but with saving them in some kind of useful format. I've seen some references to people creating interactive WebGL, but I'm looking to generate some sort of .stl or .obj file that can be cleaned up and printed.
Code looks something like this:
> library(seewave)
> library(tuneR)
> sound <- readWave("/...path.../bird_call.wav")
> spectro3D(sound, wl=1000, ovlp=85, zp=6, maga=8, palette=spectro.colors)
Which generates a nice image - see below.
But I'm lost as to how I can save this in a useful format. Is there some incredibly obvious answer I've somehow missed? Some way to send the output to WriteOBJ from the RGL package? Any help is much appreciated.
The spectro3D() function uses rgl to draw the image, so you can
just use rgl::writeOBJ("file.obj").

How to output a chart from Nielsen?

I saw an interesting chart on engadget today made by Nielsen:
http://www.engadget.com/2011/07/28/nielsen-android-leads-us-smartphone-market-with-39-percent-shar/
original source: http://blog.nielsen.com/nielsenwire/online_mobile/in-u-s-smartphone-market-android-is-top-operating-system-apple-is-top-manufacturer/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+NielsenWire+%28Nielsen+Wire%29
I'd love for someone to replicate it if possible and show the R code. Basic packages or ggplot2 would be great.
I like that the boxes are proportional, that's a key feature :)
Thanks!
You can find several implementations in R under the name of 'mosaic chart'. E.g.:
require("vcd")
data(HairEyeColor)
mosaic(HairEyeColor, shade = TRUE)
Se some examples on e.g. quickR, but searching the R graph gallery is also a good option.
In ggplot2, you can find a sample on learnr's blog.
I have also done some tweaks in ggplot2, please find the attached plot below. It is in Hungarian, but if you are interested, I could clean up the code and post is somewhere.
UPDATE: I have searched for my old script based on comment and uploaded it to pastebin. Sorry, no code clean up and it is quite messy, as I had to make it up for mass reporting from SPSS data files, but I hope you could use it. The usage is simple: load all functions (e.g.: run all lines in R with the source(...) function), and you could generate a mosaic chart of any data frame by specifying two variable names in the parameters of ggMosaicChart(). The plot will be saved to a png file in the working directory (no easy resize in R of the plot as lots of manual tweaks are done to arrange text nicely).
I have translated the strings to English, a basic example (included in the above code) of the mtcars data set:
Count, row- and column percent and also Pearson residuals are shown for each cell.
It's called treemap. R project has packages named "treemap" or "portfolio" for it. Here is how to do: http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/

Resources