Pages (Desktop)

Pages (Mobile)

Fixing the default plot window on Linux for high DPI displays

Running R on Linux with a high-DPI display and finding that the default plot window is too small and looks terrible?

Click read more to find out how to fix it!

Fixing the plot window on Linux

I recently got a new laptop which I am running Linux on (Fedora). The laptop has a high-DPI display, and one of the first issues I ran in to when running R, was that the default plot window looked awful.

The plot window was too small, and the text/graphics that were produced suffered the dreaded "jaggies". Of course, any plots that are intended for publication should be produced using a better graphics device (e.g. pdf()), but when you want to do quick plots, the screen device is most convenient.

The first fix is to make the size of the plot window bigger, and the solution is found on Stack Overflow. To change the plot window size, you need to edit the ~/.Xresources file found within your home directory, and add the following code:

R_x11*geometry: 1000x1000-0+0

This will change the plot window size to 1000 by 1000 pixels. The -0+0 changes the position of the window, and moves it to the top right of the screen.

You can customise these values to whatever you want. On my laptop, I use R_x11*geometry: 1400x1400-400+0 to give a bigger plot window, which appears at the top of my screen, 400 pixels from the right.

In order to ensure these changes take effect, run the following code in the terminal:

$ xrdb -merge ~/.Xresources

The second fix involves changing the default "pointsize" of the screen plot device, which for Linux is x11(). The pointsize argument affects the size of everything that is plotted on screen. This can be done within R by setting the option before you use plot, for example:

> x11(pointsize=24)

However, this will reset each time you start R. To have these changes take affect every time you start R, you'll need to edit your ~/.Rprofile file in your home directory to add the following code:

setHook(packageEvent("grDevices", "onLoad"), function(...) grDevices::X11.options(pointsize=24))

These changes should make plots look a lot nicer on screen.

© Benjamin Bell. All Rights Reserved. http://www.benjaminbell.co.uk

No comments

Post a Comment

Comments are moderated. There may be a delay until your comment appears.