I'm creating a histogram in R using RStudio:
h_mostSuccesfulPlayers = hist(mostSuccessfulPlayers$player_ht,
main = "Visine najuspješnijih igrača",
xlab = "Visina igrača [cm]",
ylab = "Frekvencija",
breaks = 5,
col = "palegreen")
I want that plot to not be spread over the whole page width but to only cover e.g. 50% of its width, if that sounds clear. Can I do that, possibly without using any additional libraries?
CodePudding user response:
You can set graphics parameter mar, see help("par"):
mar
A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) 0.1.
In the example below I set the margins, in lines, to the double of their default values. But first save the default value. Compare the plot area with the default, plotted in the end.
x <- rnorm(1e3)
mar_default <- par()$mar
old_par <- par(mar = 2*mar_default)
hist(x)
par(old_par)
hist(x)
CodePudding user response:
We could use the layout function:
Create a matrix then plot. Note if you use c(2,1) the order will be changed.
Here an example with monk data:
new_frame <- layout(matrix(c(1,2), ncol=2))
h_mostSuccesfulPlayers = hist(mtcars$mpg,
main = "Visine najuspješnijih igrača",
xlab = "Visina igrača [cm]",
ylab = "Frekvencija",
breaks = 5,
col = "palegreen")


