STAA 566 Assignment 1 ggplot

Author

EmilyStarer

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5     ✓ purrr   0.3.4
✓ tibble  3.1.3     ✓ dplyr   1.0.7
✓ tidyr   1.1.3     ✓ stringr 1.4.0
✓ readr   2.0.0     ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()

Attaching package: 'MASS'
The following object is masked from 'package:dplyr':

    select

You can add options to executable code like this

     Date                 Campaign ROAS Sales Spend
1  1/1/21                  BRANDED   28  1192  7742
2  1/1/21                    LOCAL    3    27  1472
3  1/1/21                 RLSA/DSA   13    29   339
4  1/1/21 SHOPPING/PERFORMANCE MAX   19   251  1462
5  2/1/21                  BRANDED   23   905  6560
6  2/1/21                    LOCAL    3    22  1312
7  2/1/21                 RLSA/DSA   54   114   328
8  2/1/21 SHOPPING/PERFORMANCE MAX   19   278  1421
9  3/1/21                  BRANDED   43   926  3173
10 3/1/21                    LOCAL    5    26   944
#make ggplot
media_plot <- ggplot(data=mediadata,
                     mapping=aes(x=Sales,
                                 y=ROAS,
                                 color=Campaign)) + 
              geom_point(aes(size=Spend),
                                  alpha=.5,
                                  shape=16)
                     
#scale axis
media_plot <- media_plot + scale_y_continuous(breaks = seq(0,60,by=10))


media_plot <- media_plot + scale_x_continuous(breaks = seq(0,7500,by=1000))

#adjust legends
media_plot <- media_plot + guides(size=guide_legend(title="Amount Spent"),
                    color=guide_legend(title="Campaign Type"))

#add title
media_plot <- media_plot + labs(title="Sales Performance by Campaign Type",
                                subtitle=strwrap(paste0("Campaigns based on targeting criteria and placement. Return on Ad Spend calculated as Sales / Media Spend.")))
#print
media_plot