Repository navigation
Expand file tree
/
Copy pathvisualization.R
More file actions
74 lines (51 loc) · 1.55 KB
/
Copy pathvisualization.R
File metadata and controls
74 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## Data visualization in R ##
# draw one point
plot(1, 5)
# draw two points
plot(c(1, 9), c(4, 11))
# Multi-points
plot(c(10, 20, 30, 40), c(30, 70, 80, 90))
x <- c(10, 20, 30, 40)
y <- c(30, 70, 80, 90)
plot(x, y)
# dots in a sequence
point <- plot (1 : 15)
plot(5 : 25)
point
# drawing line
plot(1:15, type = "l", main = "Data visualization",
xlab = "The x axis", ylab = "The y axis")
# adding color
plot(1:15, col = "red", cex = 0.5)
# shape format
plot(1:15, pch=13, cex=1) # PCH = < 25
# Colors for lines
plot(10:20, type = "l", col = "yellow")
# The width of the line
plot(10:20, type = "l", lwd = 4, col = "brown", lty = 6)
# example of multiple lines
first_line <- c(2,3,4,5,5,6,7)
second_line <- c(3,5,8,11, 13)
plot(first_line, type = "l", col = "green", lwd = 3)
lines(second_line, type = "l", col = "blue", lwd = 3)
# Pie chart in R
new_pies <- c(15, 25, 35, 45)
# labels for the pie chart
new_labels <- c("Banana", "Apple", "Watermelon", "Mango")
# colors for pies
new_colors <- c("yellow", "red", "green", "orange")
# print the pie chart
pie(new_pies, main = "Fruits", label = new_labels,
col = new_colors, init.angle = -32)
# explanation box below the chart
legend("bottomright", new_labels, fill = new_colors)
# Bar charts
x <- c(10, 20, 30, 40)
y <- c(30, 70, 80, 90)
barplot(y, names.arg = x, col = "Lightblue", density = 120,
width = c(2, 3, 4, 5), horiz = TRUE)
# Histograms
degrees <- c(15, 17, 9, 11, 14, 30, 25)
# create hist
hist(degrees, xlab = 'The x-axis', ylab = 'The y-axis', col = 'Lightblue',
border = 'Blue')