R - Resize ggplot graph in jupyter

Using R in jupyter's notebook, I first set the size of the graph everywhere. Secondly, I would like to build one plot with a different size.

## load ggplot2 library library("ggplot2") ## set universal plot size: options(repr.plot.width=6, repr.plot.height=4) ## plot figure. This figure will be 6 X 4 ggplot(iris, aes(x = Sepal.Length, y= Sepal.Width)) + geom_point() ## plot another figure. This figure I would like to be 10X8 ggplot(iris, aes(x = Sepal.Length, y= Sepal.Width)) + geom_point() + HOW DO i CHANGE THE SIZE? 

As you can see, I would like to change the second chart (and only the second chart) to 10X8. How to do it?

Sorry for the potentially dumb question, since sketch size is usually not a problem in Rstudio.

+13
source share
3 answers

Here you go:

 library(repr) options(repr.plot.width=10, repr.plot.height=8) ggplot(iris, aes(x = Sepal.Length, y= Sepal.Width)) + geom_point() 
+7
source

If options is the only available mechanism for resizing the shape, then you should do something like this to set and restore the settings as they were:

 saved <- options(repr.plot.width=10, repr.plot.height=8) ggplot(iris, aes(x = Sepal.Length, y= Sepal.Width)) + geom_point() options(saved) 
0
source

I found another solution that allows you to set the size of the graph, even when you create graphs inside a function or loop:

 pl <- ggplot(iris, aes(x = Sepal.Length, y= Sepal.Width)) + geom_point() print(pl, vp=grid::viewport(width=unit(10, 'inch'), height=unit(8, 'inch')) 
0
source

Source: https://habr.com/ru/post/1270513/


All Articles