Подтвердить что ты не робот

Qplot и сглаживание в R

Я использую библиотеку ggplot2 и работаю с командой qplot Я знаю, что могу сохранить свой результат в виде файла с сглаженным изображением, используя следующую команду после моего qplot

ggsave(file="filename.png")

Но как насчет моего ЖК-дисплея? есть ли способ увидеть сюжет на мониторе как сглаженный гppah?

4b9b3361

Ответ 1

В Windows нет встроенного сглаживания. Я не знаю, планируется ли это для будущих выпусков или нет. Вы можете получить графическое устройство на основе Каира из пакетов cairoDevice или Cairo; однако сначала вам нужно установить GTK+:

Загрузите и установите Gtk+ 2.12.9 Runtime Environment Revision 2 из http://gladewin32.sourceforge.net/

Другой вариант - использовать графику на основе Java через JGR (http://jgr.markushelbig.org/). Я думаю, что также разрабатывается устройство на базе Qt.

Ответ 2

Как отмечали другие, встроенное графическое устройство R не делает сглаживание. Но в настоящее время легко установить графическое устройство Cairo, которое делает.

На консоли R:

install.packages('Cairo',,'http://www.rforge.net/')

Чтобы проверить:

plot(rnorm(1000)) # non-antialiased (on Windows)
library('Cairo')
CairoWin()
plot(rnorm(1000)) # antialiased!

Подробнее

Ответ 3

Хорошо, я только что проверил. Я ошибся в своем предыдущем комментарии. От help(x11), где доступно множество деталей - новые устройства на Каире имеют доступ к сглаживанию:

x11 пакет: grDevices R Документация

X Window System Graphics

Описание:

 ‘X11’ starts a graphics device driver for the X Window System
 (version 11).  This can only be done on machines/accounts that
 have access to an X server.

 ‘x11’ is recognized as a synonym for ‘X11’.

Использование:

 X11(display = "", width, height, pointsize, gamma, bg, canvas,
     fonts, xpos, ypos, title, type, antialias)

 X11.options(..., reset = FALSE)

Аргументы:

[...]

 fonts: X11 font description strings into which weight, slant and
      size will be substituted.  There are two, the first for fonts
      1 to 4 and the second for font 5, the symbol font.  See
      section ‘Fonts’. 

[...]

 antialias: for cairo types, the typeof anti-aliasing (if any) to be
      used.  One of ‘c("default", "none", "gray", "subpixel")’. 

[...]

Подробнее:

 The defaults for all of the arguments of ‘X11’ are set by
 ‘X11.options’: the ‘Arguments’ section gives the ‘factory-fresh’
 defaults.

 The initial size and position are only hints, and may not be acted
 on by the window manager.  Also, some systems (especially laptops)
 are set up to appear to have a screen of a different size to the
 physical screen.

 Option ‘type’ selects between two separate devices: R can be built
 with support for neither, ‘type = "Xlib"’ or both.  Where both are
 available, types ‘"cairo"’ and ‘"nbcairo"’ offer

    * antialiasing of text and lines.

    * translucent colours.

    * scalable text, including to sizes like 4.5 pt.

    * full support for UTF-8, so on systems with suitable fonts you
      can plot in many languages on a single figure (and this will
      work even in non-UTF-8 locales).  The output should be
      locale-independent.

 ‘type = "nbcairo"’ is the same device as ‘type="cairo"’ without
 buffering: which is faster will depend on the X11 connection.
 Both will be slower than ‘type = "Xlib"’, especially on a slow X11
 connection as all the rendering is done on the machine running R
 rather than in the X server.

 All devices which use an X11 server (including the ‘type = "Xlib"’
 versions of bitmap devices such as ‘png’) share internal
 structures, which means that they must use the same ‘display’ and
 visual.  If you want to change display, first close all such
 devices. 

[... и многое другое...]

Ответ 4

Если у вас установлен Cairo (см. другие ответы), чтобы сохранить его как сглаженный PNG, просто измените свой код на:

ggsave(file="filename.png", type="cairo-png")

как указано здесь.

Но с какой целью вы хотите "увидеть график на мониторе как сглаженный график" или "анти-алиас окна моего графика"? Если вы имеете в виду, например, в окне "Графики" (вкладка) в RStudio, я не уверен, что это можно сделать, оно служит в основном как предварительный просмотр. Я предлагаю вам сохранить график в файл, а затем использовать этот файл для его отображения или для каких-либо других целей.