Data Visualization in R (original) (raw)

Last Updated : 10 Apr, 2026

Data visualization is the process of representing data using charts, graphs and maps to make information easier to understand. It helps identify patterns, trends and relationships within large datasets. In R, data visualization is widely used because of its strong statistical foundation and graphical capabilities.

Types of Data Visualizations

Some of the various types of visualizations offered by R are:

1. Bar Plot

There are two types of bar plots: horizontal and vertical which represent data points as horizontal or vertical bars of certain lengths proportional to the value of the data item. They are generally used for continuous and categorical variable plotting. By setting the horiz parameter to true and false, we can get horizontal and vertical bar plots respectively.

**Horizontal Bar Plot

R `

barplot(airquality$Ozone, main = 'Ozone Concenteration in air', xlab = 'ozone levels', horiz = TRUE)

`

**Output:

**Vertical Bar Plot

R `

barplot(airquality$Ozone, main = 'Ozone Concenteration in air', xlab = 'ozone levels', col ='blue', horiz = FALSE)

`

**Output:

**Use Cases:

2. Histogram

A histogram shows the distribution of continuous data by grouping values into intervals called bins. It helps understand data spread and shape.

R `

data(airquality)

hist(airquality$Temp, main ="La Guardia Airport's Maximum Temperature(Daily)", xlab ="Temperature(Fahrenheit)", xlim = c(50, 125), col ="yellow", freq = TRUE)

`

**Output:

**Use Cases:

3. Box Plot

A box plot visually summarizes statistical properties of data, including:

data(airquality)

boxplot(airquality$Wind, main = "Average wind speed at La Guardia Airport", xlab = "Miles per hour", ylab = "Wind", col = "orange", border = "brown", horizontal = TRUE, notch = TRUE)

`

**Output:

**Multiple Box Plots

R `

boxplot(airquality[, 1:4], main ='Box Plots for Air Quality Parameters')

`

**Output:

Box-Plot

Multiple Box Plots

**Use Cases:

4. Scatter Plot

A scatter plot is composed of many points on a Cartesian plane. Each point denotes the value taken by two parameters and helps us easily identify the relationship between them.

R `

data(airquality)

plot(airquality$Ozone, airquality$Month, main ="Scatterplot Example", xlab ="Ozone Concentration in parts per billion", ylab =" Month of observation ", pch = 19)

`

**Output:

**Use Cases:

5. Heat Map

Heatmap is defined as a graphical representation of data using colors to visualize the value of the matrix. heatmap() function is used to plot heatmap.

R `

data <- matrix(rnorm(25, 0, 5), nrow = 5, ncol = 5)

colnames(data) <- paste0("col", 1:5) rownames(data) <- paste0("row", 1:5)

heatmap(data)

`

**Output:

heatmap

Heat Map

6. Map visualization

Here we are using maps package to visualize and display geographical maps using an R programming language.

R `

install.packages("maps") library(maps) map(database = "world")

df <- data.frame( city = c("New York", "Los Angeles", "Chicago", "Houston", "Phoenix"), lat = c(40.7128, 34.0522, 41.8781, 29.7604, 33.4484), lng = c(-74.0060, -118.2437, -87.6298, -95.3698, -112.0740) )

points(x = df$lng, y = df$lat, col = "Red")

`

**Output:

-Map-in-R

Map visualization in R

7. 3D Graphs

Here we will use preps() function, This function is used to create 3D surfaces in perspective view. This function will draw perspective plots of a surface over the x–y plane.

R `

cone <- function(x, y){ sqrt(x ^ 2 + y ^ 2) }

x <- y <- seq(-1, 1, length = 30) z <- outer(x, y, cone)

persp(x, y, z, main="Perspective Plot of a Cone", zlab = "Height", theta = 30, phi = 15, col = "orange", shade = 0.4 )

`

**Output:

3D-Graphs-in-R

3D Graphs in R

You can download the complete code from here.

Applications

Advantages

R has the following advantages over other tools for data visualization:

Limitations