Hi there,
In order to test my skills I tried tried to create a simple function and with the output make a plot.
The function
I thought of was very simple, I want to visualize revenue given two input variables, n_customers
& price
both vectors.
# Setup Libs
library(tidyverse)
# Setup Revenue Function
revenue_projection <- function(n_customers= 100,price = 1){
revenue <- n_customers * price * 12
return(revenue)
}
# Customer & License Price Iteration variables
n_customers <- seq(60,600,60)
price <- seq(150,185,5)
#So I'm able to create the data frame and utilize the function correctly:
price %>% purrr::map(revenue_projection,n_customers) %>% head(3)
#> [[1]]
#> [1] 108000 216000 324000 432000 540000 648000 756000 864000 972000
#> [10] 1080000
#>
#> [[2]]
#> [1] 111600 223200 334800 446400 558000 669600 781200 892800 1004400
#> [10] 1116000
#>
#> [[3]]
#> [1] 115200 230400 345600 460800 576000 691200 806400 921600 1036800
#> [10] 1152000
Created on 2021-06-24 by the reprex package (v2.0.0)
My issue was not understanding how to "cycle"/ "for loop" ability with ggplot()
Here is what I thought of:
# My issue was with the plotting;
# Plot x = n_customers vs y = revenue_projection, price by color.
price %>% ggplot(
aes(x = n_customers,
y = purrr::map(revenue_projection,n_customers),
color = price
)) + geom_line()
#> Error in price %>% ggplot(aes(x = n_customers, y = purrr::map(revenue_projection, : could not find function "%>%"
Created on 2021-06-24 by the reprex package (v2.0.0)
Any insight would be greatly appreciated and thank you for your time!