When I create a plot in Jupyter using the ggplot2
R package, I get a link to the chart that says "View PDF" instead of the chart being presented inline.
I know that traditionally in IPython Notebook you were able to show the charts inline using the %matplotlib
magic function. Does Jupyter have something similar for R and ggplot2?
What do I need to do to show the graph inline versus as a link to a PDF?
The inline option with the %matplotlib magic function renders the plot out cell even if show() function of plot object is not called. The show() function causes the figure to be displayed below in[] cell without out[] with number. Now, add plt. show() at the end and run the cell again to see the difference.
plotnine is based on ggplot2 from the R programming language, so if you have a background in R, then you can consider plotnine as the equivalent of ggplot2 in Python. In this tutorial, you'll learn how to: Install plotnine and Jupyter Notebook. Combine the different elements of the grammar of graphics.
Using R in a Jupyter NotebookTo run a Jupyter Notebook with R, you need to create a conda environment and activate the kernel so Jupyter can recognize it. Then you can work with the R language in a notebook.
You can show the graphs inline with this option.
options(jupyter.plot_mimetypes = 'image/png')
You can also produce pdf files as you would regularly in R, e.g.
pdf("test.pdf")
ggplot(data.frame(a=rnorm(100,1,10)),aes(a))+geom_histogram()
dev.off()
There are currently some issues with producing ggplot2 outputs using the IRkermel. There is an open issue on GitHub about it. The only workaround at the moment appears to be using PDF, jpg, png outputs for your plots.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With