library(ggplot2) ggplot(data = diamonds, aes(x = cut)) + geom_bar() ggplot(data = diamonds, aes(x = carat, y = price)) + geom_point() # Create dummy dataset dummy_data <- data.frame( dummy_metric = cumsum(1:20), date = seq.Date(as.Date("1980-01-01"), by="1 year", length.out=20) ) # Plot the data using ggplot2 package ggplot(data = df.dummy_data, aes(x = date, y = dummy_metric)) + geom_line() library(dplyr) library(ggplot2) diamonds_ideal <- filter(diamonds, cut=="Ideal") diamonds_ideal <- select(diamonds_ideal, carat, cut, color, price, clarity) diamonds_ideal <- mutate(diamonds_ideal, price_per_carat = price/carat) disordered_data <- data.frame(num = c(2,3,5,1,4)) arrange(disordered_data, num) summarize(diamonds_ideal, avg_price = mean(price, na.rm = TRUE) ) library(ggplot2) ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() library(caret) model.mtcars_lm <- train(mpg ~ wt, data = mtcars, method = "lm") # coefficients for slope, intercept coef.icept <- coef(model.mtcars_lm$finalModel)[1] coef.slope <- coef(model.mtcars_lm$finalModel)[2] # Plot scatterplot and regression line ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_abline(slope = coef.slope, intercept = coef.icept, color = "red") # if use the k-nearest neighbor technique, we could use the method = "knn"