Learn/R Programming/Data Visualization

Base R Graphics

Topic: Base Graphics

Advertisement

Introduction

R's base graphics system provides a flexible way to create plots. It's built into R with no additional packages needed.

Basic Plots

# Scatter plot
plot(x, y)

# Line plot
plot(x, y, type = "l")

# With options
plot(x, y, 
     main = "Title",
     xlab = "X Axis",
     ylab = "Y Axis",
     col = "blue",
     pch = 19)

Plot Types

# Histogram
hist(data)

# Box plot
boxplot(data)

# Bar plot
barplot(height)

# Density plot
plot(density(data))

Adding Elements

plot(x, y)

# Add points
points(x2, y2)

# Add lines
lines(x, fitted)

# Add text
text(x, y, labels)

# Add legend
legend("topright", legend = c("A", "B"))

Multiple Plots

# Side by side
par(mfrow = c(1, 2))
plot(x1, y1)
plot(x2, y2)

# Reset
par(mfrow = c(1, 1))

Summary

Base graphics offer flexible plotting. Use these functions for quick visualizations.

Advertisement

Advertisement

Need More Practice?

Get personalized R programming help from ChatWhole's AI-powered platform.

Get Expert Help →