Last active
September 26, 2017 07:32
-
-
Save aravindhebbali/f5cd1315826bd44466a15444456ea61d to your computer and use it in GitHub Desktop.
Data Visualization: Scatter Plots
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
# scatter plot | |
plot(mtcars$disp, mtcars$mpg) | |
# add title and axis labels | |
plot(mtcars$disp, mtcars$mpg, | |
main = 'Displacement vs Miles Per Gallon', | |
xlab = 'Displacement', ylab = 'Miles Per Gallon') | |
# point shape | |
plot(mtcars$disp, mtcars$mpg, pch = 6) | |
# shape based on number of levels of a third variable | |
plot(mtcars$disp, mtcars$mpg, pch = nlevels(factor(mtcars$cyl))) | |
# shape based on a third categorical variable | |
plot(mtcars$disp, mtcars$mpg, pch = unclass(mtcars$cyl)) | |
# point size | |
plot(mtcars$disp, mtcars$mpg, cex = 1.5) | |
# color | |
# shape between 0 and 21 | |
plot(mtcars$disp, mtcars$mpg, pch = 5, col = 'blue', bg = 'red') | |
# shape between 22 and 25 | |
plot(mtcars$disp, mtcars$mpg, pch = 24, col = 'red', bg = 'blue') | |
# color based on a third variable | |
plot(mtcars$disp, mtcars$mpg, pch = 5, col = factor(mtcars$cyl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment