Created
May 8, 2016 03:38
-
-
Save complxalgorithm/19e00b8fcbfe1379d7aa5257d0dba3f6 to your computer and use it in GitHub Desktop.
Demonstration of different graphs in R.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use 26 since it’ll never actually equal 26 | |
# Floor will return integers; stores in vector | |
nums <- c(floor(runif(20, min=-10, max=26))) | |
# Give the chart file a name | |
png(file = “boxplotrand.png”) | |
# Plot the graph, using vector nums from first question | |
boxplot(y ~ x, data = nums, xlab = “X Values”, | |
ylab = “Y Values”, main = “Values”) | |
# Save the file | |
dev.off() | |
# Get library | |
library(plotrix) | |
# Produce vectors of 5 values | |
q <- nums[c(1:4)] | |
r <- nums[c(5:8)] | |
s <- nums[c(9:12)] | |
t <- nums[c(13:16)] | |
u <- nums[c(17:20)] | |
# For loops | |
for ( i in q ) { | |
sumq <- 0 | |
sumq <- sumq + q[i] | |
} | |
for ( j in r ) { | |
sumr <- 0 | |
sumr <- sumr + r[j] | |
} | |
for ( k in s ) { | |
sums <- 0 | |
sums <- sums + s[k] | |
} | |
for ( m in t ) { | |
sumt <- 0 | |
sumt <- sumt + t[m] | |
} | |
for ( n in u ) { | |
sumu <- 0 | |
sumu <- sumu + u[n] | |
} | |
# Vector of sums | |
x <- c(sumq, sumr, sums, sumt, sumu) | |
labels <- c(“Sum of No. 1-4”, “Sum of No. 5-8”, “Sum of No. 9-12”, | |
“Sum of No. 13-16”, “Sum of No. 17-20”) | |
png(file = “PieChart.jpg”) | |
pie3D(x,labels = labels, explode = 0.1, main = “Sums of First Four Numbers in Vector”) | |
dev.off() | |
# Give chart file a name | |
png(file = “histogramtemps.png”) | |
# Create histogram, using vector nums from the first question | |
hist(nums,xlab = “Temperature”,col = “yellow”,border = “blue”) | |
# Save file | |
dev.off() | |
# Give chart file a name | |
png(file = “linegraphsales.jpg”) | |
# Plot graph, using vector nums from first question | |
plot(nums,type = “o”, col = “red”,main = “Sales in Millions”) | |
# Save file | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment