Last active
September 26, 2017 07:46
-
-
Save aravindhebbali/ea80f20e798e25b3adfc9ff1e87ed311 to your computer and use it in GitHub Desktop.
Data Visualization: Line Graphs
This file contains 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
# data | |
head(AirPassengers) | |
# plot | |
data <- head(AirPassengers) | |
plot(data, type = 'l') | |
plot(data, type = 'b') | |
plot(data, type = 'o') | |
plot(data, type = 'c') | |
# color | |
plot(data, type = 'l', col = 'blue') | |
plot(data, type = 'b', col = 'blue') | |
# line type | |
plot(data, type = 'l', lty = 3) | |
plot(data, type = 'l', lty = 'dashed') | |
# line width | |
plot(data, type = 'l', lwd = 2.5) | |
# enhance points | |
plot(data, type = 'b', pch = 23, col = 'red', cex = 1.5) | |
# different color for line and points | |
plot(data, type = 'l', col = 'red') | |
points(data, pch = 23, col = 'blue', bg = 'green', cex = 1.5) | |
# additional lines | |
data1 <- c(7.2, 7.6, 6.8, 6.5, 7) | |
data2 <- c(6.8, 7.2, 7.8, 7, 6.2) | |
plot(data1, type = "b", col = "blue") | |
lines(data2, type = "b", col = "red") | |
# modify axis range | |
plot(data1, type = "b", col = "blue", ylim = c(5, 9)) | |
lines(data2, type = "b", col = "red") | |
# putting it all together | |
plot(data1, type = "b", col = "blue", | |
ylim = c(5, 9), main = 'Line Graph', | |
xlab = 'Index', ylab = 'Data') | |
lines(data2, type = "b", col = "red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment