Problems with Plotting in jupyter notebook using sparkmagic R

I'm trying to use ggplot2 in jupyter notebook
R:Version: "R-3.5.2_2018-12-20"

library(ggplot2)
p <- ggplot(data.frame(x = 1:5, y = 1:5), aes(x, y)) + geom_point()
plot(p)
null device
1

How can I create graphs and not getting nulldevice?

Referred here from support.rstudio.com

1 Like

You can't (or shouldn't) use plot() with a ggplot object, just put p instead.

2 Likes

Hi, this is what I get with your example after the following steps:

options(bitmapType='cairo')
library(ggplot2)
p <- ggplot(data.frame(x = 1:5, y = 1:5), aes(x,y)) + geom_point()
null device
1
p
Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : cannot open file 'Rplots.pdf' Calls: <Anonymous> -> print.ggplot -> grid.newpage -> <Anonymous>

version of cairo:
cairo.x86_64 1.14.8-2.el7 @base
cairo-devel.x86_64 1.14.8-2.el7 @base
these are the capabilities():
jpeg png tiff tcltk X11 aqua
TRUE TRUE FALSE TRUE FALSE FALSE
http/ftp sockets libxml fifo cledit iconv
TRUE TRUE TRUE TRUE FALSE TRUE
NLS profmem cairo ICU long.double libcurl
TRUE FALSE TRUE FALSE TRUE TRUE

How did you install the R kernel on Anaconda?

Try running this command on a Anaconda prompt console

conda install -c r r-essentials 

I have no problem at all running your code

Hi,
I send you my different versions of R, Cairo and so on. It could be an installation problem:

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Db2 Warehouse

Matrix products: default
BLAS: /mnt/blumeta0/R-Install/lib64/R/lib/libRblas.so
LAPACK: /mnt/blumeta0/R-Install/lib64/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.5.2

Cairo packages:
cairo.x86_64 1.14.8-2.el7 @base
cairo-devel.x86_64 1.14.8-2.el7 @base

I use jupyter notebook with livy server and sparkmagic

After I installed cairo, I reinstalled R.
You suggested
conda install -c r r-essentials
we don't have conde , we use pip.

Do I have to install conda, or is there a way to use pip for this and what is the reason to ruun this special install command.
And do I have to install RStudio?
Thanks for your quick answers

Sorry for that, I was assuming that you were using Anaconda distribution to install jupyter notebook, I have no experience with jupyter notebook and your specific setup, maybe you would have better luck looking on a jupyter related forum.

Hi Andrés, one last question, can you send me your environment setup in which it is possible to use plot? I will try to set up a machine.
Thanks in advance
Monika

I use jupyter notebooks on Windows, I have it installed using Anaconda distribution, but this method also works for macOS and linux systems.