-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlots.R
60 lines (44 loc) · 1.8 KB
/
Plots.R
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
#MAK Example Code - 10 June 2015 - Successfully addded to github.
setwd("C:/Users/MAK/Desktop/R/R_MAK")
getwd()
# Read car and truck values from tab-delimited autos.dat
#autos_data <- read.table("C:/R/autos.dat", header=T, sep="\t")
autos_data <- read.csv("autos.csv", header = TRUE)
# Define colors to be used for cars, trucks, suvs
plot_colors <- c(rgb(r=0.0,g=0.0,b=0.9), "red", "forestgreen")
# Start PDF device driver to save output to figure.pdf
pdf(file="autosfigure.pdf", height=3.5, width=5)
# Trim off excess margin space (bottom, left, top, right)
par(mar=c(4.2, 3.8, 0.2, 0.2))
# Graph autos using a y axis that uses the full range of value
# in autos_data. Label axes with smaller font and use larger
# line widths.
plot(autos_data$cars, type="o", col=plot_colors[1],
ylim=range(autos_data), axes=F, ann=T, xlab="Days",
ylab="Total", cex.lab=0.8, lwd=2)
# Make x axis tick marks without labels
axis(1, lab=F)
# Plot x axis labels at default tick marks with labels at
# 45 degree angle
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,
labels=c("Mon", "Tue", "Wed", "Thu", "Fri"),
xpd=T, cex=0.8)
# Plot y axis with smaller horizontal labels
axis(2, las=1, cex.axis=0.8)
# Create box around plot
box()
# Graph trucks with thicker red dashed line
lines(autos_data$trucks, type="o", pch=23, lty=1, lwd=2,
col=plot_colors[2])
# Graph suvs with thicker green dotted line
lines(autos_data$suvs, type="o", pch=24, lty=1, lwd=2,
col=plot_colors[3])
# Create a legend in the top-left corner that is slightly
# smaller and has no border
legend("topleft", names(autos_data), cex=0.8, col=plot_colors, pch=21:23,
lty=1:1, lwd=2, bty="n");
# Turn off device driver (to flush output to PDF)
dev.off()
# Restore default margins
par(mar=c(5, 4, 4, 2) + 0.1)
#----- CODE ENDS ------