0
$\begingroup$

I want to add chart labels to different datasets that are chosen via manipulate. I have a hierarchical data set that I imported from excel and broke down into subgroups using nested associations. There are three different campaign types (manual, auto, brands), each of which has three search types (PP,RoS,Top) and each of those search types holds 13 metrics. Below is an example of the manual campaign organizational structure:

manualPlacement = Association[  "PP" -> Association[
101520 -> Association[  
  Impressions -> data101920[[22 ;; 25, 3]],
  Clicks -> data101920[[22 ;; 25, 4]],
  Cpc -> data101920[[22 ;; 25, 5]],
  Spend -> data101920[[22 ;; 25, 6]],
  Sales -> data101920[[22 ;; 25, 7]],
  ACoS -> data101920[[22 ;; 25, 8]],
  RoAS -> data101920[[22 ;; 25, 9]],
  Orders -> data101920[[22 ;; 25, 10]],
  Units -> data101920[[22 ;; 25, 11]],
  Conversion -> data101920[[22 ;; 25, 12]],
  CTR -> data101920[[22 ;; 25, 13]
    ]]],

This organizational structure is used for manual (PP,RoS,Top), and repeated for auto and brands. In order to compare two data sets side by side on one graph, I created a duplicate of the entire structure labeled "manualPlacement2" etc. The campaigns are organized by

campaign =Association[
"ManualCampaign" -> manualPlacement, 
"AutoCampaign" -> autoPlacement, 
"BrandCampaign" -> brandPlacement]

The names of the campaign names (the labels I want to put in the graph) are stored as the first value of each element which are stored by

labels = Association[
ManualLabel -> data101920[[10 ;; 13, 1]], 
AutoLabel -> data101920[[2 ;; 5, 1]],
BrandsLabel -> data101920[[6 ;; 9, 1]]]

labels2 was also created to label the second set of data categorized by campaign2. The metric data I want to access can be retrieved by

campaign[campaignType("ManualCampaign","AutoCampaign","BrandCampaign"),
placementType ("PP","RoS","Top"),
dateRange (the week of the data imported, theres only one week for test purposes), 
metric (impessions,clicks,etc.)]

The goal of this whole ordeal is to create an interactive graph using Manipulate to be able to substitute the plotted datasets via drop down menu, which can be achieved by the code below. The only problem is the labeling I used is applied to both datasets, and the only way to differentiate them that I could think of was to use a legend for the second data set, however this gets confusing to look at as there is the incorrect label on the bottom of the second dataset.

Manipulate[
 BarChart[{
   campaign[campaignType, placementType, dateRange, metric],
   campaign2[campaignType2, placementType2, dateRange2, metric2]},
  ChartLabels -> {labelType},
  ChartLegends -> {labelType2}
  ],
 {campaignType, {"ManualCampaign", "AutoCampaign", "BrandCampaign"}},
 {placementType, {"PP", "RoS", "Top"}},
 {dateRange, {101520}},
 {metric, {Impressions, Cpc, Clicks}},
 {labelType, {labels[ManualLabel], labels[AutoLabel], 
   labels[BrandsLabel]}},
 {campaignType2, {"ManualCampaign", "AutoCampaign", "BrandCampaign"}},
 {placementType2, {"PP", "RoS", "Top"}},
 {dateRange2, {101520}},
 {metric2, {Impressions, Cpc, Clicks}},
 {labelType2, {labels2[ManualLabel], labels2[AutoLabel], 
   labels2[BrandsLabel]}},
 ControlType -> PopupMenu
 ]

When this is run, the output chart looks like this: enter image description here

As you can see, the labelyType is displayed for both sets of data below the bars, and the only way to differentiate the second dataset is using the legend. Is there a way to label the datasets individually on the bottom without having to use the legend? Additionally what is a good method to making a chart title that auto-updates when the metrics are changed? Thanks in advance.

$\endgroup$

1 Answer 1

1
$\begingroup$

Perhaps something like:

ds = Dataset @ AssociationThread[{"Manual", "Auto", "Brand"},
       AssociationThread[{"52TD", "54SQ", "54TD", "54Vee"}, #] & /@
          {{1, 2, 3, 4}, {5, 6, 7, 3}, {4, 3, 2, 1}}]

enter image description here

Manipulate[BarChart[ds[{campaignType1, campaignType2}], 
    LabelStyle -> 16, 
    ImageSize -> Large, 
    ChartLabels -> {{campaignType1, campaignType2}, Normal@Keys[ds[campaignType1]]}, 
    PlotLabel -> Row[{campaignType1, campaignType2}, "Vs."]], 
 {{campaignType1, "Manual"}, Normal @ Keys[ds]}, 
 {{campaignType2, "Auto"}, Normal @ Keys[ds]}, 
 ControlType -> PopupMenu]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.