legend:
legend("the location in the graph, like bottomright", legend, fill: the color of different level, cex)
add lines:
abline(int, slope)
lines( )
cuts <- levels(small_diam$cut)
col_counter <- 1
for (i in cuts) {
this_cut <- small_diam$cut == i
this_data <- small_diam[this_cut, ]
this_lm <- lm(log(this_data$price) ~ log(this_data$carat))
abline(this_lm, col = col_counter)
col_counter <- col_counter + 1
}
point:
points(x, y)
# simulate 10000 standard normal
Z <- rnorm(10000)
head(Z)
# plot a hist of Z w/ the true density overlayed on the plot
hist(Z, breaks = 30)
# create a normal curve
## need to consider the y-axis is FREQUENCY or DENSITY
z.plot <- seq(-5, 5, length = 10, probability = T)
plot(z.plot, dnorm(z.plot), col = "purple", lty = 1, lwd = 1)
# plot sin(x) cos(2x)+1 from -2pi,2pi in same graph
x.plot <- seq(-2*pi, 2*pi, length = 100)
plot(x.plot, sin(x.plot), col = "green", type = "l", ylim = c(-1.5, 2.5))
lines(x.plot, cos(x.plot*2)+1, col = "red", type = "l")