Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R ggplot resize plot area window

I have problems resizing the plot area. If you look at the following example you will see that the label of the x-axis "x" is out of the range of the plot window/area and therefore not visible any longer. I tried to resize the plot window/area with

dev.new(width=10, height=10)

but that does not increase the space of the white boundary outside the actual plot area. I also saved the plot as PDF hoping that the label "x" will reappear in the PDF but that's also not the case.

Is it somehow possible to increase that particular area?

library(ggplot2)
df <- data.frame(x=1:10, y=1:10) 
ggplot(df, aes(x,y)) + geom_point() + 
  opts(axis.title.x = theme_text(size = 14, hjust = 0.5, vjust = -5))
like image 520
user969113 Avatar asked Feb 12 '26 10:02

user969113


1 Answers

To change the size of the plotting area available for axis labels and text, you can use

opts(plot.margin = unit(c(2, 2, 2, 2), "cm"))

to specify the margin size of each side of the plot.

like image 62
smillig Avatar answered Feb 15 '26 15:02

smillig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!