Based Plot: Histogram

Full Screen

TipThe CRAP principles

The CRAP principles are a set of design guidelines that help make layouts more organized, visually appealing, and easy to understand. CRAP stands for:

  1. Contrast: Create visual contrast between elements, like varying sizes, colors, and font styles. This helps highlight important information and makes it easier for viewers to distinguish different sections.

    • Example: Use bold, bright colors for headings and lighter shades for body text.
  2. Repetition: Repeat certain design elements, such as fonts, colors, or shapes, throughout the layout to create unity and consistency.

    • Example: Use the same font and color scheme across all pages of a website.
  3. Alignment: Arrange elements in a structured way to create a clean and organized appearance. Proper alignment helps the viewer’s eyes flow naturally across the page.

    • Example: Align all text to the left, right, or center to maintain consistency rather than mixing alignments.
  4. Proximity: Group related items together to show their connection and make the information easier to scan.

    • Example: Place similar buttons (like β€œSubmit” and β€œCancel”) close to each other.

Using these CRAP principles can greatly enhance the readability, clarity, and visual appeal of designs for websites, posters, or any printed materials.

πŸ“Š Summary of R Commands Used (Histograms & Density Plots)

1. hist(): Creates a histogram (frequency distribution).

NoteMain arguments:
  • x β†’ numeric vector of data

  • breaks β†’ number or placement of bins

  • main β†’ plot title

  • xlab, ylab β†’ axis labels

  • col β†’ bar fill color (name or hex code)

  • border β†’ bar border color

  • probability = TRUE β†’ y-axis shows density instead of frequency

  • add = TRUE β†’ overlay histogram on an existing plot

2. lines()

  • Adds lines to an existing plot.

  • Often used with density() to add a smoothed curve.

Key arguments:

  • col β†’ line color

  • lwd β†’ line width

  • lty β†’ line type (solid, dashed, dotted, etc.)

3. density()

  • Estimates the probability density function of a numeric variable.

  • Returns an object that can be plotted with plot() or lines().

4. plot(): General plotting function. Used here for density plots.

NoteKey arguments:
  • xlab, ylab β†’ axis labels

  • main β†’ title

  • col β†’ line color

  • lwd β†’ line width

  • lty β†’ line type

  • xlim, ylim β†’ axis limits

5. legend(): Adds a legend to a plot.

NoteArguments:
  • Position β†’ "topleft", "topright", "bottomleft", "bottomright"

  • legend β†’ text labels

  • fill β†’ colors used in plot

  • col, lwd β†’ match lines or bars in the plot

6. box()

  • Adds a box around the plot area (optional).

  • col can set the box border color.

7. rug()

  • Adds tick marks at actual data values along the x-axis.
  • Useful in combination with density plots.

8. rgb()

  • Defines colors with transparency.

  • rgb(red, green, blue, alpha) where values range 0–1.

  • Example: rgb(1, 0, 0, 0.5) = semi-transparent red.

10. rnorm(): Generates random numbers from a normal distribution.

NoteArguments:
  • n β†’ number of values

  • mean β†’ mean of the distribution

  • sd β†’ standard deviation

11. Advanced hist() with plot = FALSE

  • hist(..., plot = FALSE) β†’ stores histogram object without drawing.

  • Access h$mids (bin midpoints) and h$counts (bin frequencies) for custom coloring.