Skip to content

Instantly share code, notes, and snippets.

@aravindhebbali
Last active September 26, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aravindhebbali/ea80f20e798e25b3adfc9ff1e87ed311 to your computer and use it in GitHub Desktop.
Save aravindhebbali/ea80f20e798e25b3adfc9ff1e87ed311 to your computer and use it in GitHub Desktop.
Data Visualization: Line Graphs
# 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