Advice and Considerations
From Wilke
Additional choices to make in your visual representations
- Titles, captions, axis labels
- Providing context via legends, annotations, background grids and axis ticks, reference lines, labeling
- Text size (readability, relative to figure)
Telling a story
- A set of observations, facts, events presented in a specific order such that they create an emotional reaction in the audience.
- “If we don’t provide a clear story ourselves, then our audience will make one up.”
- Will usually require multiple visualizations
From Data Feminism
While many data and science communicators promote the idea of data as neutral and exhort data visualization to be objective (true?), Klein and D’Ignazio reject this, arguing instead that data visualization should embrace emotion and embodiment.
- Visualization as rhetoric: data visualizations arise from a set of “choices about the selection and representation of reality” – it is rhetorical whether it intends to persuade or not.
- Data visceralization: representations of data to be experienced beyond sight (e.g., emotionally as well as physically, audio as well as sight)
- Periscopic’s visualization of gun deaths
Interactivity with ggplotly
plotly
is a high-level interface to plotly.js, based on d3.js which provides an easier-to-use interface for interactive graphics.
There are two main approaches to initialize a plotly object:
- transforming a
ggplot2
object with ggplotly()
– this converts a ggplot()
object into an interactive plot_ly()
object, but it won’t work for every figure.
- setting up aesthetics mappings with
plot_ly()
directly – this is a different plotting system, so harder to learn, but more customizable.
To the Script!
plotly
will automatically include the ability to
- hover over a point to see the included values
- zoom in by selecting (click+drag) a region of the plot
- subset to specific groups by clicking their names in the legend
- download as a png file
See the Sievert book for more!
Putting Stuff online
R Markdown can be rendered to formats other than HTML, but HTML files are easy to host online and share! Two possibilities
- RPubs allows free hosting of static single-file R Markdown content – just click the “Publish” button on your html file!
- GitHub Pages, if you’re a GitHub user, allows hosting of Markdown and HTML files from the GitHub repository (that’s how my other class page is hosted)
- A web server like Netlify (Here’s a great webinar on sharing R markdown files, and other sources, on Netlify)
See the chapter in Xie’s R Markdown book for more!
Tables!
Sometimes you just want a table, especially in an interactive report (R Markdown style). Tables are great for
- Looking up or compare individual observations/values
- Including detail and summary values
- Displaying precise values
Options for creating better tables:
- knitr::kable + kableExtra: The
kable()
function, “a very simple table generator,” is defined by the knitr
package. Probably the easiest “pretty” table in R Markdown.
- DT::datatable: The
datatable()
function provides an R interface to the JavaScript library DataTables to produce interactive tables; automatically searchable, sortable.
To the Script!
See the Keye’s post for more on gt
, reactable
and others!