background preloader

Graphics

Facebook Twitter

Ggplot

Rvisualization.com. Easy pictograms using R. Making infographics using R and Inkscape - Vik's Blog. I have been making charts with R for almost as long as I have been using R, and with good reason: R is an amazing tool for filtering and visualizing data.

Making infographics using R and Inkscape - Vik's Blog

With R, and particularly if we use the excellent ggplot2 library, we can go from raw data to compelling visualization in minutes. But what if we want to give our visualizations an extra kick? What if we want to do some manual retouching? I had long resisted this, thinking that conveying the data was the major concern, and it was up to viewer to parse it how they saw fit. As visualizations become more and more important, it is evident to me that merely conveying the data is not enough; these days, a visualization must also be visually attractive. Complex Graphics (lattice)

Please direct questions and comments about these pages, and the R-project in general, to Dr.

Complex Graphics (lattice)

Tom Philippi. Introduction Clear communication of pattern via graphing data is no accident; a number of people spend their careers developing approaches based on human perceptions and cognitive science. While Edward Tufte and his "The Visual Display of Quantitative Information" is more widely known, William Cleveland's "The Elements of Graphing Data" is perhaps more influential: reduced clutter, lowess or other smoothed curves through data, banking to 45° to emphasize variation in slopes, emphasizing variability as well as trends, paired plots to illustrate multiple components of the data such as fits and resuduals, and dot plots all come from his work.

Moving Past Default Charts. Controlling Axes of R Plots. (This post is part of the #cumpa series of blog posts and tweets I am writing leading up to SPSA. For more information, see this blog post. To follow along, subscribe to my blog here or follow me on Twitter here. To engage in the conversation, reply to this tweet.) R has powerful graphical capabilities and I use it in all my papers to plot data and illustrate theoretical ideas. The default plot function, however, doesn't give the reader needed control over the axis labels.

Custom point style in plot. Math Annotation in R. R List of Colours. Animating the Metropolis algorithm. The Metropolis algorithm, and its generalization (Metropolis-Hastings algorithm) provide elegant methods for obtaining sequences of random samples from complex probability distributions.

Animating the Metropolis algorithm

When I first read about modern MCMC methods, I had trouble visualizing the convergence of Markov chains in higher dimensional cases. So, I thought I might put together a visualization in a two-dimensional case. I’ll use a simple example: estimating a population mean and standard deviation. We’ll define some population level parameters, collect some data, then use the Metropolis algorithm to simulate the joint posterior of the mean and standard deviation.

Then, to visualize the evolution of the Markov chains, we can make plots of the chains in 2-parameter space, along with the posterior density at different iterations, joining these plots together using ImageMagick (in the terminal) to create an animated .gif: Visualizing optimization process. One of the approaches to graph drawing is application of so called force-directed algorithms.

Visualizing optimization process

In its simplest form the idea is to layout the nodes on plane so that all edges in the graph have approximately equal length. Working with Geospatial Data (and ggplot2) This is a follow-up blog-post to an earlier introductory post by Steven Brey: Using R: Working with Geospatial Data.

Working with Geospatial Data (and ggplot2)

In this post, we’ll learn how to plot geospatial data in ggplot2. Why might we want to do this? Well, it’s really about your personal taste. DiagrammeR. SparkTable. Directlabels documentation - home. The R graph Gallery. Take Screenshot of Webpage using R. The av Package: Production Quality Video in R. At rOpenSci we are developing on a suite of packages that expose powerful graphics and imaging libraries in R.

The av Package: Production Quality Video in R

Our latest addition is av – a new package for working with audio/video based on the FFmpeg AV libraries. This ambitious new project will become the video counterpart of the magick package which we use for working with images. install.packages("av") av::av_demo() The package can be installed directly from CRAN and includes a test function av_demo() which generates a demo video from random histograms. Colorspace: New Tools for Colors and Palettes. A major update (version 1.4.0) of the R package colorspace has been released to CRAN, enhancing many of the package's capabilities, e.g., more refined palettes, named palettes, ggplot2 color scales, visualizations for assessing palettes, shiny and Tcl/Tk apps, color vision deficiency emulation, and much more.

colorspace: New Tools for Colors and Palettes

Overview The colorspace package provides a broad toolbox for selecting individual colors or color palettes, manipulating these colors, and employing them in various kinds of visualizations. Version 1.4.0 has just been released on CRAN, containing many new features and contributions from new co-authors. A new web site presenting and documenting the package has been launched at At the core of the package there are various utilities for computing with color spaces (as the name conveys). The colorspace package provides three types of palettes based on the HCL model: More detailed overviews and examples are provided in the articles: Installation install.packages("colorspace") Rayshader: Introducing 3D ggplots with rayshader. As rayshader gracefully rotates into its second year, I’m happy to announce the release of a feature I've been teasing for a while: 3D ggplots!

rayshader: Introducing 3D ggplots with rayshader

It's been a long time coming, but the wait was worth it--I promise. Creating this feature was a logical extension of rayshader’s core competency–using elevation matrices to generate raytraced 3D maps of topographic data. Specifically, this tool generates 3D visualizations by transforming the color or fill aesthetics already defined in a ggplot2 object into the third dimension, and then maps the original plot onto that 3D surface. Exporting nice plots in R. A vital part of statistics is producing nice plots, an area where R is outstanding.

Exporting nice plots in R

The graphical ablility of R is often listed as a major reason for choosing the language. It is therefore funny that exporting these plots is such an issue in Windows. This post is all about how to export anti-aliased, high resolution plots from R in Windows. There are two main problems when exporting graphics from R: Anti-aliasing is not activated in Windows R (this does not apply to Linux or Mac).

My previous solution to this problem has been to export my graph to a vector graphic (usually the SVG format), open it in Inkscape, and then export it to the resolution of choice. The post has several sections: Exporting. Saving R Graphics across OSs. R is known for it’s amazing graphics.

Saving R Graphics across OSs

Not only ggplot2, but also plotly, and the other dozens of packages at the graphics task view. There seems to be a graph for every scenario. However once you’ve created your figure, how do you export it? This post compares standard methods for exporting R plots as PNGs/PDFs across different OSs. Unicode Characters in ggplot2 PDF Output. Ragg 0.1.0. We’re stoked to announce the release of ragg 0.1.0 on CRAN. ragg provides a set of high quality and high performance raster devices, capable of producing png, tiff, or ppm files, or a matrix of raw color values directly within R. ragg is part of our broader effort to improve graphics performance and quality in R at all levels of the stack, so that you’ll benefit no matter what plotting framework you choose to use.

Other parts of this efforts have been: Developing the devoid package to allow more precise benchmarking of plotting code.Multiple improvements to rendering speed in grid in the latest R release (3.6.0).Performance improvements in ggplot2 3.2.0 both broadly and for sf plotting specifically.Performance improvements in gtable 0.3.0. The devices An R graphic device is an object that receives instructions from the graphic engine in R and translates that into some meaningful format for viewing.

Plotly Shiny Gallery. Comparing plotly & ggplotly plot generation times. The plotly package. A godsend for interactive documents, dashboard and presentations. d3panels. Trelliscopejs. Trelliscope is a visualization approach based on the idea of “small multiples” or “Trellis Display”, where data are split into groups and a plot is made for each group, with the resulting plots arranged in a grid. This approach is very simple yet is considered to be “the best design solution for a wide range or problems in data presentation”.

Trelliscope makes small multiple displays come alive by providing the ability to interactively sort and filter the plots based on summary statistics computed for each group. TrelliscopeJS by Ryan Hafen. Interactive Viewing of Spatial Objects in R. Creating Interactive Plots with R and Highcharts – RStudio.