0% found this document useful (0 votes)
10 views7 pages

Advanced Data Visualization Techniques

Advanced graphics involve creating complex visualizations that include interactivity, customization, and dynamic elements. Key R packages for advanced graphics include ggplot2, Plotly, and Lattice, which offer various functionalities for data representation. Customization options in R allow users to modify titles, labels, colors, and layouts to enhance the visual appeal and informativeness of plots.

Uploaded by

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

Advanced Data Visualization Techniques

Advanced graphics involve creating complex visualizations that include interactivity, customization, and dynamic elements. Key R packages for advanced graphics include ggplot2, Plotly, and Lattice, which offer various functionalities for data representation. Customization options in R allow users to modify titles, labels, colors, and layouts to enhance the visual appeal and informativeness of plots.

Uploaded by

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

ADVANCE GRAPHICS

>Advanced graphics typically refer to the creation of more complex and sophisticated
visualizations that go beyond basic plots and charts

>The creation of intricate and highly customizable visual representations of data

>The graph type include probability plots, mosaic plots and correlograms.

Advanced graphics include:


 Interactivity
 Customization
 Complex Data structures=
 3D Visualization
 Dynamic Visualization

Packages:
1.ggplot2: ggplot2 is a powerful and widely used package for creating static and publication
quality graphics.

[Link]: Ploty is an interactive and web-based visualization package that enables the creation of
dynamic, interactive and high-quality plots.

[Link]: Lattice is a package for creating Trellis graphics, which are particularly useful for
conditioning plots, including scatter plots and line plots.

[Link]: ggvis is an interactive graphics package that integrates seamlessly with ggplot2.

[Link]: dygraphs is a package specifically designed for time-series data

[Link]: rBokeh is an R interface to Bokeh visualization library in python.

Customizing Plots:

Customizing plots in R allows us to create visually appealing and informative graphics tailored to
the specific needs.

Basic Plot Customization:


 Adjusting the plot title using the “main” parameter.
 Customizing axis labels using the xlab and ylab parameters.
 Modifying axis limits using the xlim and ylim parameters.
 Changing axis ticks and labels using functions like ‘axis’ and ‘at’

Color Customization:
 Setting colors for points, lines or bars using the ‘col’ parameters.
 Creating color palettes with functions like ‘’’rainbow’, ‘[Link]’ and ‘[Link]’
Text Customization:
 Modifying text properties such as font size, font family, and font style using the ‘cex’ and
family parameters.
 Adding annotations and text labels using functions like text and ‘mtext’

Legend Customization:
 Modifying legends label and position using the legend functions and x and y parameters.
 Changing legend titles and text properties using the ‘’title’ and ‘[Link]’ parameters.

Layout Customization:
 Adjusting the layout of multiple plots using functions like ‘par’ and ‘layout‘
 Creating multi-panel plots using packages like ‘gggplot2’ and ‘’’gridExtra’.

Line and Marker Customization:


 Modifying line types and widths using the ‘lty’ and ‘’lwd’ parameters.
 Changing point shapes, sizes and colors using the ’pch’ an ‘cex’ parameters.

Background Customization:
 Adjusting the background color using the ‘bg’ parameter.
 Adding grid lines using functions like ‘abline’ and grid.

Changing plot Title and Axis Labels


x <- 1:10
y <- x^2
plot(x, y, main = "Custom Plot Title", xlab = "X Axis Label", ylab = "Y-Axis Label")

Modifying Plot Colors and Line Types


x <- 1:10
y <- x^2
plot(x, y, type = "l", col = "blue", lwd = 2, lty = 2)

Adding Text and Annotations


plot(1:10, 1:10, main = "Adding Annotations")
text(5, 7, "Center Text", col = "blue", cex = 1.5)
arrows(5, 7, 7, 7, col = "red", length = 0.1)

Colors:
Colors can be defined using various formats including predefined color names, hexadecimal color
codes. RGB vales and other color models.

Predefined Color Name:


R provides a set of standard color names, such as “red, “blue”,
“green” and “purple”, which can be directly in plotting functions.

Hexadecimal Color Codes:


Hexadecimal color codes represent colors using a
combination of red, green and blue (RGB) values in a hexadecimal format. Ex: #FF0000

RGB Values:
Colors can be defined using RGB values, which specify the intensity of red, green and blue
components on a scale of 0 to 255. For instance, the color red can be defined as
RGB (255, 0, 0).

RGBA Values:
Similar to RGB, the RGBA color model includes an additional alpha
channel that represents the opacity or transparency of the color.

eg:
plot(1:5, col="blue", pch=19)

plot(1:5, col="#FF0000", pch=19)

plot(1:5, col=rgb(255,0,0, maxColorValue=255), pch=19)

Customizing Traditional R Plots:

Customizing traditional R plots involves modifying various graphical parameters to make plots
more visually appealing, informative and suitable for specific data and research objectives.

Title and Labels:

 Main Title(main): Add a title to describe the content or purpose of the plot.

 X-axis Label(xlab) and Y-axis Label(ylab): Label the axes to provide content for the data
being displayed.
Colors and Line Types:

 Color(col): Change the line or point color to differentiate multiple data series.

 Line Type(lty): Adjust the line type (solid, dashed etc) to distinguish lines.

 Point Character(pch): Modify the point character to change the shape of data points.

 Line Width(lwd): Increase or decrease the line width to make lines more visible or subtle.

 Axis Limits (xlim, ylim): Adjust the range of the x-axis and y-axis to focus on specific
data intervals.

 Legends (legend): Add a legend to identify data series or categories in the plot. customize the
legends position and labels.
 Grid Lines(grid): Add grid lines to improve readability and make it easier to estimate values.

 Text Labels(text): Place text labels on the plot to provide additional information and
annotations.

Background and Margins:

 Plot Margin(par(mar)): Adjust the margin size around the plot area to make room for titles and
labels.

 Background Color(bg): Change the background color of the plot area.

Specialized Text Notation:


Specialized text notation in R refers to using specific symbols, formatting or characters to
represent special characters, mathematical equations or other notations within text strings

1. Greek Letters:
Greek letters can be included in text strings using the expression function. For ex,
expression(alpha) represents the Greek letter alpha.

Ex of using Greek letter alpha in a plot title:

plot(1:10, main=expression("Scatterplot witH" ~ alpha ~"Symbol"))

2. Subscripts and Superscripts:


Subscripts and superscripts can be added to text using the substitute and paste functions

#Ex of using substitute and subscripts in a plot

plot(1:10, main=substitute(paste("H"[2], "O"), list()))

3. Special Characters:
Special characters such as degree symbol (0) or copyright symbol (©), can be included
using their Unicode code points.

#Example of using special characters in a plot title


plot(1:10, main = "Temperature (\u00B0C) vs. Time")

4. Mathematical Equations:
Mathematical equations can be included within text using LaTeX notation.
For Ex $\alpha + \beta = \gamma$ represents a mathematical equation.
plot(1:10, main = expression("Linear Regression Model: " ~ y == alpha + beta * x +
epsilon+sigma))
5. Scientific Notation:
Scientific notation can be used to format numbers with exponents
plot(1:10, main = expression(2.5 %*% 10^-3 ~ "kg"))

Specialized Label Notation:

Specialized label notation to format and customize the appearance of text labels in your plots.

Specialized label notation allows you to add mathematical symbols, Greek letters, subscripts,
superscripts and other formatting to your text annotations

plot(1:10, xlab = expression(alpha), ylab = expression(beta))

Plotting region:

The “plotting region” region specifies the size and location of the plot within a graphical device
such as a window or file.

Defining a plotting Region with par.


The ‘par’ function to set graphical parameters, including the size and location of the plotting
region

Common parameters for defining the plotting region include:

 mfrow or mfcol: Specifies the number of rows and columns for multiple plots in a grid.

 mar: Sets the margins around the plotting region

 oma: Specifies the outer margins of the entire plot

 plt: Defines the location of the plotting region within the graphical device.

# Set up a 2x2 grid


par(mfrow = c(2, 2))

# Create four different plots


plot(1:10, main = "Plot 1")
plot(10:1, main = "Plot 2")
plot(runif(10), main = "Plot 3")
plot(rnorm(10), main = "Plot 4")
par(mfrow = c(1, 2))

Plotting Margins:
Plotting margin using the ‘par’ function. The par function is used to set various graphical
parameters for plotting. To change the margin sizes, you can modify the ‘’mar’ parameter, which
respects the number of lines of margin to be specified on the four sides of the plot(botton, left, top,
right).

x<-1:10
y<-x^2

par(mar=c(5, 4, 4, 2) + 0.1)

plot(x, y, type="l", col="blue", main="Plot with Adjusted Margins")

Point-and –click:

A point-and-click coordinate interaction in an R plot to use the locator function.

The locator function is to interactively click on a plot, and it records the coordinates of the points
where you click.

The locator function interactively selects points or coordinates by clicking on a plot

# Create data
x <- 1:10
y <- x^2
plot(x, y, type = "p", col = "blue", pch = 16, main = "Interactive Point Selection")
points <- locator(3)
cat("Clicked Coordinates:\n")
print(points)

3D Scatter Plots:
3D scatter plots in R to visualize data points in a three-dimensional space, typically with points
representing data points in a 3D space, the scatterpot3d function from the scatterplot3d package
to create 3D scatter plots, a dimensions and the points are displayed in the three dimensional
coordinate system.

library(plotly)

x <- rnorm(100)
y <- rnorm(100)
z <- rnorm(100)

# Create a 3D scatter plot


plot_ly(x = x, y = y, z = z, type = 'scatter3d', mode = 'markers')

Plotting in Higher Dimensions:


Plotting in higher dimensions is a challenging task, as visualizing data beyond three dimensions
directly on a 2D plot is not feasible. However, there are several techniques in R that can help
visualize and analyze high-dimensional data:

[Link] Matrices: Use the pairs function to create a matrix of scatterplots, where each
variable is plotted against every other variable. This provides an overview of pairwise
relationships in the data.

[Link] Coordinate Plots: Represent each observation as a line that traverses across a set of
parallel axes, with each axis representing a different variable. This allows for the visualization of
multivariate data points.

[Link] 3D visualization: Packages like rgl and plotly enable the creation of interactive 3D
plots, allowing for the exploration of data in tree dimensions.

[Link] Clustering Dendrogram: Use the heatmap2 function in the gplots package to create
a dendrogram that displays hierarchical relationships within the data.

You might also like