2009-12-13 5 views
16

J'utilise la bibliothèque ggplot2 et je travaille avec la commande qplot Je sais que je peux sauver ma sortie comme un fichier image lissée en utilisant la commande suivante après mon qplotqplot et anti-aliasing en R

ggsave(file="filename.png") 

Mais qu'en est-il de mon écran LCD? est-il possible de voir une intrigue sur le moniteur comme anti-alias?

+0

Je pense que c'est entre vous et votre gestionnaire de fenêtres. –

+7

Existe-t-il un moyen de dire à R l'anti-alias de mes fenêtres de traçage? – Mark

Répondre

13

Sous Windows, il n'y a pas d'anti-aliasing intégré. Je ne sais pas si c'est prévu pour les prochaines versions ou non. Vous pouvez obtenir un périphérique graphique basé sur Cairo à partir des packages cairoDevice ou Cairo; Cependant, vous devez installer GTK+ premier:

Téléchargez et installez Gtk+ 2.12.9 Runtime Environment Revision 2 de http://gladewin32.sourceforge.net/

Une autre option serait d'utiliser des graphiques Java par JGR (http://jgr.markushelbig.org/). En outre, un appareil basé sur Qt est en cours de développement, je pense.

+0

Fantastique, merci beaucoup – Mark

+2

J'ai installé Cairo sans avoir à installer GTK +, sur Windows 7 avec R 3.1.1 64-bit. L'anti-massage est agréable. – jnm2

3

Ok, je viens de vérifier. J'avais tort dans mon commentaire précédent. De help(x11) où beaucoup de détails sont disponibles - les nouveaux dispositifs basés au Caire ont anti-aliasing disponibles:

paquet x11: grDevices R Documentation

X Window Graphics système

Description de :

‘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’. 

Utilisation:

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

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

Arguments:

[...]

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")’. 

[...]

Détails:

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. 

[... et plus ...]

+0

Très bien, maintenant voici ma question: j'obtiens une erreur quand je tape X11 (type = "cairo") Je reçois "Erreur dans X11 (type =" cairo "): argument (s) non utilisé (type =" cairo ") "J'ai cairo chargé mais je ne sais pas comment je peux changer mon X11. J'utilise R 2.9.2 sur un Win XP. Ai-je besoin de détruire tout mon système et d'obtenir un anti-aliasing sur mon écran? – Mark

+0

J'étais un peu inquiet à propos de cette partie. Je sais que le Caire vient de Gnome/Gtk et est à la maison sur Linux, mais je pensais que c'était multi-plateforme. Qu'est-ce que vous obtenez quand vous appelez 'capabilities()' dans votre session R sur XP? J'ai un vrai «cairo» juste à la fin. –

+0

Je reçois faux, mais merci de toute façon, voyage très intéressant. Je vais l'essayer sur un Ubuntu plus tard. Merci encore d'avoir regardé ça. – Mark

12

Comme d'autres l'ont mentionné, le périphérique graphique intégré de R ne fait pas d'anti-aliasing. Mais de nos jours, il est facile d'installer le périphérique graphique du Caire qui le fait.

Sur la console R:

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

Pour tester:

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

More

2

Si vous avez Caire installé (voir les autres réponses), l'enregistrer comme un anti alias PNG, il suffit de changer votre code pour:

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

tel que spécifié here.

Mais dans quel but voulez-vous "voir un tracé sur le moniteur comme un graphique anti-aliasé" ou "anti-alias mes fenêtres de tracé"? Si vous voulez dire que dans la fenêtre Plots (onglet) dans RStudio, je ne suis pas sûr que cela puisse être fait, il sert essentiellement comme un aperçu. Je vous suggère de sauvegarder le graphique dans un fichier, puis d'utiliser ce fichier pour l'afficher ou pour tout autre usage.