Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the size of R plots in Jupyter?

I am wondering how to configure Jupyter to plot a smaller figure within R kernel.

I have tried using options(repr.plot.width = 1, repr.plot.height = 0.75, repr.plot.res = 300), but the result is kinda messy. It is changing the size of the plot R produced. Are there any ways I can directly configure the output graph size in Jupyter.

In other words, how can I change the size in the first figure to the size in the second figure, while not messing up the plot.

enter image description here enter image description here

like image 522
Jay Wong Avatar asked Mar 10 '17 22:03

Jay Wong


People also ask

How do I change the plot size in Jupyter Notebook R?

Changing the plot size You can change the plot size by setting the option repr. plot. width and repr.

Is Jupyter good for R?

Running R in an R Notebook is a significantly better experience than running R in a Jupyter Notebook. The advantages present in R Notebooks can also provide guidance for feature development in other Notebook software, which improves the data analysis ecosystem as a whole.


1 Answers

You need to manually set the tick size, marker size and text size. The text size and tick size can be set through the theme() function, while marker size through geom_point() function.

df_1 = data.frame(x=c(5, 6, 7, 8, 9), y = c(200, 225, 250, 270, 310))  options(repr.plot.width = 1, repr.plot.height = 0.75) ggplot(df_1, aes(x = x, y = y)) + geom_point(size = 0.3) +     theme(text = element_text(size = 3), element_line(size = 0.1)) 

enter image description here

like image 100
Jughead Avatar answered Oct 04 '22 04:10

Jughead