R Cheat



I reproduce some of the plots from Rstudio’s ggplot2 cheat sheet using Base R graphics. I didn’t try to pretty up these plots, but you should.

R cheat sheet 2021-01-30 This cheat sheet provides simple R code for data cleaning and restructuring. This cheat sheet summarizes common Stata commands for econometric analysis and provides their equivalent expression in R. References for importing/cleaning data, manipulating variables, and other basic commands include Hanck et al. (2019), Econometrics with R, and Wickham and Grolemund (2017), R for Data Science. Work with strings with stringr:: CHEAT SHEET Detect Matches strdetect(string, pattern) Detect the presence of a pattern match in a string. Strdetect(fruit, 'a') strwhich(string, pattern) Find the indexes of strings that contain a pattern match. Strwhich(fruit, 'a') strcount(string, pattern) Count the number of matches in a string. R/cheatengine: This Unofficial subreddit is for Discussion about Cheat Engine and cheats for games using Cheat Engine. Press J to jump to the feed. Press question mark to. R Programming Cheat Sheet advanced Created By: arianne Colton and Sean Chen environments Access any environment on the search list as.environment('package:base') Find the environment where a name is defined pryr::where('func1') Function environments There are 4 environments for functions. Enclosing environment (used for lexical scoping).

I use this dataset

The main functions that I generally use for plotting are

  • Plotting Functions
    • plot: Makes scatterplots, line plots, among other plots.
    • lines: Adds lines to an already-made plot.
    • par: Change plotting options.
    • hist: Makes a histogram.
    • boxplot: Makes a boxplot.
    • text: Adds text to an already-made plot.
    • legend: Adds a legend to an already-made plot.
    • mosaicplot: Makes a mosaic plot.
    • barplot: Makes a bar plot.
    • jitter: Adds a small value to data (so points don’t overlap on a plot).
    • rug: Adds a rugplot to an already-made plot.
    • polygon: Adds a shape to an already-made plot.
    • points: Adds a scatterplot to an already-made plot.
    • mtext: Adds text on the edges of an already-made plot.
  • Sometimes needed to transform data (or make new data) to make appropriate plots:
    • table: Builds frequency and two-way tables.
    • density: Calculates the density.
    • loess: Calculates a smooth line.
    • predict: Predicts new values based on a model.

All of the plotting functions have arguments that control the way the plot looks. You should read about these arguments. In particular, read carefully the help page ?plot.default. Useful ones are:

  • main: This controls the title.
  • xlab, ylab: These control the x and y axis labels.
  • col: This will control the color of the lines/points/areas.
  • cex: This will control the size of points.
  • pch: The type of point (circle, dot, triangle, etc…)
  • lwd: Line width.
  • lty: Line type (solid, dashed, dotted, etc…).

Discrete

Barplot

Different type of bar plot

Continuous X, Continuous Y

Scatterplot

Jitter points to account for overlaying points.

Add a rug plot

Add a Loess Smoother

R/cheaters

Loess smoother with upper and lower 95% confidence bands

Loess smoother with upper and lower 95% confidence bands and that fancy shading from ggplot2.

Add text to a plot

Discrete X, Discrete Y

R Cheats

Mosaic Plot

Color code a scatterplot by a categorical variable and add a legend.

par sets the graphics options, where mfrow is the parameter controling the facets.

The first line sets the new options and saves the old options in the list old_options. The last line reinstates the old options.

R Code Cheat Sheet

R Cheat

This R Markdown site was created with workflowr

Plotly's R graphing library makes interactive, publication-quality graphs. Examples of how to make line plots, scatter plots, area charts, bar charts, error bars, box plots, histograms, heatmaps, subplots, multiple-axes, and 3D (WebGL based) charts.
Plotly.R is free and open source and you can view the source, report issues or contribute on GitHub.

Write, deploy, & scale Dash apps and R data visualization on a Kubernetes Dash Enterprise cluster.
Get Pricing | Demo Dash Enterprise | Dash Enterprise Overview

More Fundamentals »
More Basic Charts »
More Statistical Charts »
More Scientific Charts »
More Financial Charts »
More Maps »
More 3D Charts »
Sheet
More Subplots »

R Cheat Sheet Data Wrangling

Add Custom Controls