Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

NAME: R B SHARAN

REG NO: 20MID0209


COURSE: CSI 3005 – Advanced Data Visualization
Techniques
SLOT: L5+L6

LAB ASSIGNMNET – 4

Scalar visualization - 2
#Dataset Preparation:
device_type <- c("Laptop", "Smartphone", "Tablet", "Laptop", "Smartphone",
"Tablet", "Laptop", "Smartphone", "Tablet", "Laptop", "Smartphone", "Tablet",
"Laptop", "Smartphone", "Tablet", "Laptop", "Smartphone", "Tablet",
"Laptop", "Smartphone")
os <- c("Windows", "Android", "iOS", "Windows", "Android", "iOS", "MacOS",
"Android", "iOS", "Windows", "Android", "iOS", "MacOS", "Android", "iOS",
"Windows", "Android", "iOS", "MacOS", "Android")
cpu_cores <- c(4, 2, 4, 4, 2, 4, 4, 2, 4, 4, 2, 4, 4, 2, 4, 4, 2, 4, 4, 2)
software_apps <- c(20, 10, 15, 25, 15, 20, 30, 20, 25, 20, 15, 10, 25, 20, 30, 20,
25, 20, 15, 10)
battery_life <- c(5, 6, 7, 5, 6, 7, 4, 5, 6, 4, 5, 6, 3, 4, 5, 3, 4, 5, 3, 4)
processor_clock_speed <- c(2.5, 1.8, 2.2, 2.7, 2.0, 2.4, 2.9, 2.2, 2.6, 3.0, 2.4, 2.8,
3.2, 2.6, 3.0, 3.4, 2.8, 3.2, 3.6, 3.0)
df <- data.frame(device_type, os, cpu_cores, software_apps, battery_life,
processor_clock_speed)
print(df)

# code
#Output

# Use head and tail

ATTRIBUTE TYPE:

Device type: Categorical (Nominal)


Operating System (OS): Categorical (Nominal)
CPU cores: Numerical (Discrete)
Software apps: Categorical (Nominal)
Battery life: Numerical (Continuous)
Processor clock speed: Numerical (Continuous)
Dependent variables:
• Battery life
• Processor clock speed

Independent Variables:
• Device type
• Operating System (OS)
• CPU cores
• Software apps

1. Histogram:

install.packages("ggplot2")
library(ggplot2)
ggplot(df, aes(x=processor_clock_speed)) +
geom_histogram(binwidth=0.2, color="black", fill="khaki")
+
ggtitle("Processor Clock Speed Histogram") +
xlab("Processor Clock Speed (GHz)") +
ylab("Frequency")
Inference:
From the histogram plot, we can see that the processor clock speed for
Smartphones and Laptops is higher compared to Tablet. This could indicate
that Smartphones and Laptops are designed using the frequency.

2) Color mapping:

Luminance color map:

Code:
ggplot(df, aes(x=os, y=device_type, fill=processor_clock_speed)) +
geom_tile(color="white", size=0.2) +
scale_fill_gradient(low="white", high="blue") +
labs(title="Processor Clock Speed by Device Type and OS",
x="Operating System", y="Device Type", fill="Processor Clock
Speed")

Graph:

Inference:

From the heat map plot, we can see that the operating system for
checking the processor clock speed for the devices such has smart
phone, laptop and tablet , where it has compared with blue colour
which represents max level and light blue colour which represents
the low level.
Zebra Color map:
Code:
zebra_colors <- colorRampPalette(c("white", "black"))(100)

ggplot(data.frame(processor_clock_speed), aes(x = 1, y =
processor_clock_speed)) +
geom_tile(aes(fill = processor_clock_speed), color = "white") +
scale_fill_gradientn(colors = zebra_colors) +
scale_x_continuous(limits = c(0.5, 1.5), expand = c(0, 0)) +
scale_y_continuous(limits = c(min(processor_clock_speed),
max(processor_clock_speed)), expand = c(0, 0)) +
labs(x = NULL, y = "Processor Clock Speed", fill = "Processor
Clock Speed") +
theme_void()

Graph:
Inference:
In these plot, we can see the black and white colour for the processor
clock speed. Where the black color represents frequent number of
appearance and white color represents the low number of appearance
of the devices used.

Rainbow color map:

Code:

ggplot(df, aes(x = device_type, y = processor_clock_speed, color =


battery_life)) +
geom_point() +
scale_color_gradientn(colors = rainbow(7)) +
labs(x = "Device Type", y = "Processor Clock Speed (GHz)", color
= "Battery Life (Hours)")
Graph:
Inference:
In these rainbow color mapping, we can see the different colours for
the battery life for the devices used. In these we can see that it
represents the processor clock speed for the devices types and violet
color represents maximum and orange color represents low level.

Gray scale:
Code:
library(ggplot2)
library(dplyr)

# Create a data frame with the provided variables


data <- data.frame(device_type, os, cpu_cores, software_apps, battery_life,
processor_clock_speed)

# Create a new column with the total count of each device type
data <- data %>% group_by(device_type) %>% mutate(total_count = n())

# Create a new column with the percentage of each device type


data <- data %>% mutate(percentage = (total_count / sum(total_count)) * 100)

# Create a bar chart with grayscale and hovering numbers


ggplot(data, aes(x = device_type, y = percentage, fill = device_type, label =
paste0(round(percentage),"%"))) +
geom_bar(stat = "identity", color = "black", width = 0.7) +
scale_fill_grey() +
labs(x = "Device Type", y = "Percentage", fill = "Device Type") +
theme_minimal() +
theme(panel.grid.major = element_blank(), panel.grid.minor =
element_blank()) +
geom_text(size=3, position = position_stack(vjust = 0.5))

Graph:

Inference:
In this grayscale plot, we can able to predict the percentage of each device types
used frequently. In these graph we can see that Tablet is frequently used device
and laptop and smartphones have equal numbers.
Texture -based:
Code:
install.packages("raster")
library(raster)

# Create a data frame with the device information


df <- data.frame(device_type, os, cpu_cores, software_apps, battery_life,
processor_clock_speed)

# Create a raster object to hold the battery life data


r <- raster(nrow=4, ncol=5, xmn=0, xmx=5, ymn=0, ymx=4, crs=CRS("+proj=utm +zone=1
+datum=WGS84"))

# Set the values of the raster object to the battery life data
values(r) <- matrix(battery_life, ncol=5)

# Define the texture patterns


patterns <- c("blue", "brown", "green", "purple", "red")

# Create a palette to map values to patterns


palette <- colorRampPalette(patterns)(length(unique(battery_life)))

# Plot the raster map with the texture patterns


plot(r, col=palette, legend=F)
Graph:

Contours:
Code:
# Load required libraries
library(ggplot2)
library(dplyr)

# Create a data frame from the vectors


data <- data.frame(device_type, os, cpu_cores, software_apps, battery_life,
processor_clock_speed)

# Calculate a smooth density surface for the data


density <- data %>%
ggplot(aes(processor_clock_speed, battery_life)) +
stat_density_2d(aes(fill = ..level..), geom = "polygon", alpha = 0.8) +
scale_fill_gradientn(colors = c("blue", "white", "red"))

# Add contour lines to the plot


contours <- density +
stat_density_2d(aes(color = ..level..), geom = "path", linejoin = "round") +
scale_color_gradientn(colors = c("blue", "white", "red"))

# Add labels and legend to the plot


final_plot <- contours +
labs(title = "Processor Clock Speed vs. Battery Life",
x = "Processor Clock Speed (GHz)",
y = "Battery Life (hours)",
fill = "Density") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5),
legend.position = "bottom")

# Display the plot


final_plot
Graph:

Inference:
In this plot, we can represent the processor clock speed and the battery life of
the devices. Where the violet colour represents the maximum level of the
battery life and where the red colour represents the low level of the battery life
for all the devices.
3. Prepare a Gantt chart for depicting the weekly tasks for
Advanced Data Visualization lab.

Code:

adv_visu <- data.frame(


task_name=c("DA 1","DA 2","DA 3","DA 4","DA 5","DA
V6","DA 7","DA 8","DA 9","DA 10"),
target=c("R-Programming I","R-Programming II","Scalar Data
Visualization-I","Scalar Data
Visualization-II","Hierarchial Data Visualization-I","Hierarchial Data
Visualization-II","Vector
Data Visualization","Spatial and Temporal Data
Visualization","Streaming Data
Visualization","Text and Multivariate Data Visualization"),
start_date=c("2023-01-12","2023-01-15","2023-01-24","2023-02-
10","2023-03-05","2023-03-
25","2023-04-04","2023-04-10","2023-04-15","2023-04-20"),
end_date=c("2023-01-22","2023-01-23","2023-01-31","2023-02-
22","2023-03-20","2023-03-
30","2023-03-07","2023-03-15","2023-04-16","2023-04-29"),
duration=c(10,8,7,12,15,5,3,5,1,9)
)
print(adv_visu)
Graph:

Inference:
In these antt chart we can able to see the different target represent
different colours and the duration for 4 months represents in these
chart and number of task represents with the colours.

You might also like