0% found this document useful (0 votes)
2 views1 page

Ggplot2 Quick Reference

This document provides a quick reference for creating basic plot types using ggplot2 in R. It includes code examples for bar charts, box plots, scatter plots, line graphs, and histograms, along with instructions for adding titles, axis labels, and applying a clean theme. Each plot type is accompanied by specific ggplot2 code to facilitate easy implementation.

Uploaded by

harjaskaur2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Ggplot2 Quick Reference

This document provides a quick reference for creating basic plot types using ggplot2 in R. It includes code examples for bar charts, box plots, scatter plots, line graphs, and histograms, along with instructions for adding titles, axis labels, and applying a clean theme. Each plot type is accompanied by specific ggplot2 code to facilitate easy implementation.

Uploaded by

harjaskaur2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ggplot2 Quick Reference – Basic Plot Types in R

Plot Type ggplot2 Code Example

Bar Chart (Count by Category) ggplot(data, aes(x = category)) +


geom_bar(fill = "skyblue")

Bar Chart (With Custom Y Values) ggplot(data, aes(x = category, y = value)) +


geom_col(fill = "coral")

Box Plot ggplot(data, aes(x = group, y = value)) +


geom_boxplot(fill = "lightgreen")

Scatter Plot ggplot(data, aes(x = var1, y = var2)) +


geom_point(color = "purple")

Line Graph ggplot(data, aes(x = time, y = value)) +


geom_line(color = "blue")

Histogram ggplot(data, aes(x = numeric_var)) +


geom_histogram(binwidth = 5, fill =
"orange")

Add Title and Axis Labels + labs(title = "Plot Title", x = "X Label", y =
"Y Label")

Clean Theme + theme_minimal()

You might also like