library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
#a Power() Function
Power <- function() {
2^3
}
Power()
## [1] 8
#b Power2() Function
Power2 <- function(x, a) {
x^a
}
Power2(3, 8)
## [1] 6561
#c Power2() Applied
Power2(10, 3)
## [1] 1000
Power2(8, 17)
## [1] 2.2518e+15
Power2(131, 3)
## [1] 2248091
#d Power3() Function
Power3 <- function(x, a) {
result <- x^a
result
}
Power3(3, 8)
## [1] 6561
#e Power3() Applied
data.frame(x = 1:10, y = Power3(1:10, 2)) %>%
ggplot(aes(x = x, y = log(y))) +
geom_point() +
geom_line() +
scale_x_continuous(breaks = 1:10, minor_breaks = NULL)

#f PlotPower() Function
PlotPower <- function(x, a, col = "black") {
ggplot(mapping = aes(x = x, y = x^a)) +
geom_point(col = col) +
geom_line(col = col) +
scale_x_continuous(labels = scales::comma_format()) +
scale_y_continuous(labels = scales::comma_format()) +
theme_light() +
labs(title = paste0("Plot of f(x) = x^", as.character(a), " (for x between ", min(x), " and ", max(x), ")"),
subtitle = "Created using the 'PlotPower()' function")
}
PlotPower(1:20, 3)

PlotPower(x = seq(1, 500, 10),
a = 2,
col = "deepskyblue3")
