How can I use Cairo to replace ggplot graphics in PowerBI - r

I am working on a ggplot graph to be used within PowerBI. I would like to use Cairo to improve the look of the graph. When using the CairoWin() function in RStudio it generates a popout window. The same happens in PowerBI. This is no good for the PowerBI dashboard as I need the Cairo generated graph to remain embedded in the dashboard replacing the current ggplot graph not as a popout.
I have tried the Cairo documentation but, no luck. Is there anyway for Cairo to replace the ggplot generated graph instead of creating a popout window?

Related

Creating plot using R under Mac OS

I use R in Mac through command line. When I need to draw some plot, R open plotting device called Quartz to display plot. It all works fine, but problem arise when I update a plot or draw a new plot based on changed plot. It looks like Quartz device does not automatically update the same. I need to close Quartz before I update my data and hit enter, so that new/modified plot can appear in Quartz.
I am wondering if this is default behaviour when R is run from command line in Mac? Is there any way to automatically update the plot in Quartz every time I update the data for plotting?
Any pointer will be highly appreciated.

Overlay plot on map background in R

I want to make a windrose plot on a specific location. Windrose can be plot with openair package
library(openair)
windRose(mydata, "ws", "wd")
or with ggplot using this function. What I am looking for, a nice way to overlay this plot on a map. I tried with ggmap (I don't have a google map API key) and leaflet. This example also I tried, the output is below.
Is there a way to overlay ggplot on leaflet map or any other ggmap way to do it nicely.
That is a multi-step process and will take a bit of tweaking to make it work the way you want but it can be done in 3 steps.
Set the background of your chart to transparent
Save a png locally
Use addLogo() from mapview package to post the image to your map and place it
For sure you will need to problem solve some as you implement this process. If you are doing this in Shiny you would want to use directory management to create and destroy the plots as data updates and be sure to make the creation of the graph reactive or observed in some way.
If you are making a nice rMarkdown dashboard, just make sure you keep track of where the png file saves and use the proper addressing.

Save viewer object rendered in RStudio as image

I created an object that is viewed in the RStudio viewer, such as chart in plotly or highcharter or a map in leaflet. I would like to save that object as a png. There are a number of ways to do this. For example, there's this method that uses webshot. It's possible to use orca. There are several methods. The problem with all of these is that the output image is slightly different than the version seen in the viewer. This is a problem for me because I need both the interactive version of the chart as well as a static version and I don't want to have to create two versions and write all the code associated with producing both to make sure each one comes out just as I need.
However, RStudio has a built-in method that can be accessed by clicking "Export -> Save as Image" in the viewer pane. I would like to use this method because it preserves the layout exactly as seen in the viewer.
I tried using R's built-in plot saving method of png, plot and devoff, but that appears to only work for plot objects, not viewer objects.
There has to be a way to reproduce the physical steps of saving as an image in RStudio programmatically, right? Doing it manually would be really time-consuming.
Here's an sample chart in plotly that shows up in the viewer.
plot_ly(z = ~volcano, type = "surface")

Is there a way to recover a ggplot2 image from a Plotly image?

I have some code that generates a plotly image in R. Previously I included this plot in a presentation using Rstudio/ioslides. The people I am collaborating with want a version in powerpoint. I am trying to use the ReporterRs package in order to create an re-producible shell powerpoint presentation with all of my plots. However ReporterRs only accepts lattice, ggplot2, and base images. Since there is a way to convert ggplot2 objects to plotly images I was hoping there was a way to go backwards. However I am stuck. I have been unable to "downgrade" my plotly plots to ggplot2. Does anyone know if there is a way to do this?
(I know I can just copy and paste them over but I would like to develop a workflow where I can create easily reproducible and replaceable plots so that I don't have to do very much work if I change the data)

How to show an iplot without opening an additional window into r shiny

I'm trying to build interactive graphs in my shiny app. The user should be able to click on bars and see where the cases are displayed in another graph for example like a scatterplot next to the barplot.
There are different r packages, that are doing a great job: iplot, rggobi, acinonyx. I also found qtlcharts, but it does not exactly what I wanted. The problem is, I can't figure out, how to integrate different iplots into my shiny app boxes. Is there any way preventing iplots from opening separate windows for the graphs?
In acinonyx you can say window=FALSE, which prevents opening the java window of the graph. But the graph isn't displayed in the box as well. You could add/move the iplot into icontainer, iVisual or iWindow, but none of them can be integrated into the shiny boxes in the ui without printing the error: unsupported data frame or doing nothing at all.
I found the answer to my question: building reactive ggplots in shiny and adding coloured layers to one plot if the other plot is clicked will do the job.

Resources