-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path09-charts.qmd
More file actions
638 lines (363 loc) · 23.8 KB
/
Copy path09-charts.qmd
File metadata and controls
638 lines (363 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# Charts {#sec-charts}
```{r, file = "R/webex.R", include = FALSE}
```
::: callout-intro
- Parts of a chart.
- Creating charts.
- Adjustments of chart parts.
- Location and size of a chart.
- Formatting a chart.
:::
Charts are an important tool in analyzing data. They can display information clearly, and their power should not be underestimated. Trends and patterns can be easily visualized, and abnormalities or fluctuations become readily apparent.
Excel offers a wide range of chart types, making it important to choose the right one. When Excel is installed, the Grouped Column chart type is the default, but this setting can be changed.
To easily create a chart in Excel, the data should be well-organized in the worksheet, ideally in a table format.
Charts can be located in two ways:
- As an object in a worksheet. This is called an **embedded chart**. The advantage is that you can view and print the chart alongside the data.
- On a special worksheet dedicated to the chart, called a **chart sheet**.
The chart's location can be changed later.
## Chart Elements {#sec-charts-elements}
A chart consists of many elements, not all of which are included by default in Excel. They can be added, moved, or deleted as needed.
{#fig-chart-elements}
The most important parts of a chart are:
Chart area (1)
: The entire chart, including all its elements.
Plot area (2)
: The rectangular area bounded by the axes, containing all data series. In the figure, this is the area with the light-colored background.
Data series (3)
: A row or column of numbers from your worksheet that are plotted in the chart. The example chart has two data series: the blue and brown colored sets. Data series have names (here, "2009" and "2010"), which form the legend.
Data point (4)
: An individual value (bar, column, point, etc.) in the chart. Each column in the chart is a data point, with a total of eight data points shown.
Category axis (5)
: The horizontal axis or X-axis. The text labels along this axis come from cells in the worksheet. In the example, the categories are "Q1," "Q2," "Q3," and "Q4."
Horizontal axis title (6)
: This title identifies the type of data along the horizontal axis. For example, if it's not clear that "Q1, Q2, Q3, Q4" represents quarters, you can add a title to clarify.
Value axis (7)
: The vertical axis or Y-axis, which usually contains numbers.
Vertical axis title (8)
: This title is important for identifying the units along the axis.
Chart title (9)
: A short text that indicates the chart's subject. It usually appears in a larger font near the top of the chart.
Legend (10)
: A box that identifies the patterns or colors assigned to the data series or categories.
Gridlines (11)
: Horizontal or vertical lines in the plot area.
Data labels (12)
: Numbers associated with data points, providing their actual values.
## Creating a Recommended Chart {#sec-charts-create}
Excel offers many chart types, and choosing the most appropriate one can be challenging. The [Recommended Charts]{.uicontrol} command can help by suggesting suitable charts for your data. Always select the data first to use this feature effectively.
:::: {#prp-charts-create}
[File]{.smallcaps}: `Bakery.xlsx`
{#fig-bakery-data}
1. Open the file.
2. Select any cell in the data area A1:D5.
::: {.callout-note title="Selecting data area"}
If the data area is contiguous (like A1:D5 here), selecting any cell within it allows Excel to automatically recognize the entire data area. If the area is not contiguous, you must select the whole data area.
:::
3. Choose [Insert \> Recommended Charts (Charts group)]{.uicontrol}.
The Insert Chart dialog box appears. The left side displays a list of Excel's recommended charts for your data, and clicking on a chart shows a preview on the right.
{#fig-chart-recommended}
4. Choose [Clustered Column \> OK]{.uicontrol}.
The chart is embedded in the worksheet, and the [Chart Design]{.uicontrol} and [Format]{.uicontrol} tabs appear on the ribbon. These tabs are only visible when the chart is selected.
A frame surrounds the chart to indicate it is selected. In the upper-right corner, three buttons allow you to add or change::
-  Chart Elements
-  Chart Styles
-  Chart Filters
::::
::: {.callout-tip title="Quick Analysis"}
An alternative, often quicker, method to insert a recommended chart is:
1. Select the data, including the headings.
2. Click the [Quick Analysis]{.uicontrol} button  at the bottom right corner of the selected range.
3. Click [Charts]{.uicontrol} and select the desired chart.
:::
## Chart Operations {#sec-charts-operations}
You can perform various operations on chart elements, depending on the specific element. For text elements, you can change the size, font, color, etc. To perform an operation, you must first select the element and then choose the operation from the menu or the right-click shortcut menu.
**Selecting a chart element**
This is usually straightforward, but it can be tricky when elements are close together.
After selecting the chart, you can select a chart element in the following ways:
- Click on the chart element.
- Use the menu [Format tab \> Chart Elements arrow (Current Selection group)]{.uicontrol}.
{#fig-chart-elements-currentselection}
::: {.callout-note title="Selected chart elements"}
1. The [Current Selection]{.uicontrol} always displays the selected element. In @fig-chart-elements-currentselection, the [Chart Area]{.uicontrol} is selected.
2. Selected parts are marked with sizing handles.\

:::
**Moving an element**
Select the element, hover the mouse pointer over its edge (not on a sizing handle), and drag it to the desired location.
**Changing dimensions**
When a resizable element is selected, it is surrounded by sizing handles. Drag a handle to change its height or width.
**Formatting an element**
Select the element and choose [Format tab \> Format Selection (Current Selection group)]{.uicontrol}. A task pane appears on the right with formatting options.
You can also access the task pane by right-clicking on the element and selecting [Format ...]{.uicontrol}.
**Applying a chart style**
Excel provides predefined formats called styles. You can apply a style using the  button.
**Deleting a chart**
Both embedded charts and chart sheets can be easily removed.
Choose one of the following options:
- Embedded chart: Select the chart and press the [Delete]{.uicontrol} key.
- Chart Sheet: Right-click on the chart sheet's tab and select [Delete]{.uicontrol} from the shortcut menu.
## Switching Rows/Columns {#sec-charts-switch-dataranges}
The source data for a chart can be arranged either with data series in columns or rows. You can easily switch between these arrangements.
In the bakery's sales data (@fig-bakery-data), the annual data is in columns, and the quarterly data is in rows. You can compare years, with each year as a data series (@fig-chart-recommended), or compare quarters, with each quarter as a data series. When creating the chart, Excel tries to guess whether the columns or rows should be the data series. If Excel's choice is incorrect, you can easily change it.
::: {#prp-charts-switch-dataranges}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the chart by clicking within the chart area.
A double border appears around the chart, and the mouse cursor changes to a cross with arrows .
3. Choose [Chart Design \> Switch Row/Column (Data group)]{.uicontrol}.
{#fig-bakery-column-quarters}
:::
## Changing Chart Location {#sec-charts-move}
You can create a chart on the same worksheet as the data (an **embedded chart**) or on a separate sheet that contains only the chart (a **chart sheet**). You can move an embedded chart by dragging it or move it to a chart sheet. This task demonstrates both methods.
:::: {#prp-charts-move}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the chart by clicking within the chart area.
A double border appears around the chart, and the mouse cursor changes to a cross with arrows .
3. Press the left mouse button and drag the chart to the desired location.
::: {.callout-tip title="Snap to grid"}
Holding down the [Alt]{.uicontrol} key while dragging snaps the chart to the worksheet's gridlines.
:::
4. Click outside the chart in the worksheet to deselect it.
5. elect the chart again and choose [Chart Design \> Move Chart (Location group)]{.uicontrol}.
{#fig-chart-move-window}
6. Select [New sheet]{.uicontrol}, name the new sheet, and click [OK]{.uicontrol}.
You can also move a chart from a chart sheet to embed it in a worksheet.
7. Select the chart in the chart sheet.
8. Choose [Chart Design \> Move Chart (Location group)]{.uicontrol}.
9. Select [Object in]{.uicontrol}, choose the worksheet, and click [OK]{.uicontrol}.
The worksheet with the embedded chart is displayed and the chart sheet is deleted.
::::
## Resizing Charts {#sec-charts-dimensions}
You can change a chart's size by dragging its sizing handles. These handles may appear as small circles, squares, or dots. When an object is selected, a rectangular frame outlines it, and sizing handles appear at each corner and the middle of each side. Corner handles allow dragging in any direction, while middle handles restrict dragging to horizontal or vertical directions. You can enlarge or shrink the chart or specify exact dimensions.
:::: {#prp-charts-dimensions}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the chart by clicking within the chart area.
3. Hover the mouse pointer over a corner point until it turns into a double-headed arrow .
4. Click the left mouse button and drag to the desired size.
::: {.callout-tip title="Snap to grid"}
Holding down the [Alt]{.uicontrol} key while dragging snaps the chart to the worksheet's gridlines.
:::
To specify exact dimensions:
5. Select the chart.
6. Choose [Format \> Height / Width (Size group)]{.uicontrol}.
{#fig-chart-dimensions}
7. Enter the desired dimensions.
8. Click outside the chart in the worksheet to deselect it.
::::
## Chart Title {#sec-charts-title}
When you create a chart, the title appears above it by default. You can select the title text and type your desired title, hide the title, or change its location.
:::: {#prp-charts-title}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the chart.
3. Choose [Chart Design \> Add Chart Element (Chart Layouts groep) \> Chart Title]{.uicontrol}.
{#fig-chart-title-options}
4. Choose [Above Chart]{.uicontrol}.
5. Double-click the title text "Chart Title" and replace it with your own text for example "Sales Bakery".
::: {.callout-tip title="Chart title options"}
- Selecting `None` removes the chart title.
- You can move the chart title by dragging it.
- You can format the title by selecting it, right-clicking, and choosing [Format Chart Title]{.uicontrol}.
:::
::::
:::: {#prp-charts-title2}
**Faster method**
1. Select the chart.
2. Click the Chart Element button  next to the chart to see a list of chart elements.
3. Check [Chart Title]{.uicontrol} to immediately add the title to the chart.
{#fig-chart-elements-title}
::: {.callout-tip title="Chart elements options"}
- An arrow next to a chart element indicates a drop-down menu with more options.
- Checked elements are present in the chart. Unchecking an element removes it.
:::
::::
The following tasks will primarily use this faster method.
## Legend {#sec-charts-legend}
A legend identifies the patterns or colors representing data series in a chart. By default, if applicable, the legend appears on the right. You can remove it or drag it to another location.
::: {#prp-charts-legend}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
The [Chart elements]{.uicontrol} button  provides the following legend options:
- Right
- Top
- Left
- Bottom
- None (by deselecting)
Like the chart title, you can drag and format a legend.
Experiment with the options.
:::
## Axis Titles {#sec-charts-axis-titles}
Axis titles are labels along the horizontal and vertical axes that help explain the data.
::: {#prp-charts-axis-titles}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
The [Chart elements]{.uicontrol} button  provides the following options for Axis Titles:
- Primary Horizontal
- Primary Vertical
1. Add titles for both axes.
2. Change the horizontal title in "Time".
3. Change the vertical title to "Sales (x 1000)".
:::
## Data Labels {#sec-charts-data-labels}
Data labels are numbers at the data points that display the actual values.
::: {#prp-charts-data-labels}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
The following options are available for data labels:
{#fig-datalabels-options}
Experiment with these options. In @fig-bakery-datalabels) you see the display for the [Outside End]{.uicontrol} option.
{#fig-bakery-datalabels}
:::
## Gridlines {#sec-charts-gridlines}
Gridlines are horizontal and vertical lines that extend from the axes across the chart's plot area. They make the data easier to read by providing visual guides. You can display gridlines for major or minor intervals on the axes.
::: {#prp-charts-gridlines}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
The following options are available for gridlines:
{#fig-gridline-options}
Hover the mouse over the options to preview the results in the chart.
:::
## Plot Area {#sec-charts-plotarea}
The plot area is the rectangular area of the chart that displays the charted data. It is bounded by the axes and includes the axes but not the titles. You can format the plot area with a colored background and border.
::: {#prp-charts-plotarea}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the plot area, right-click, and choose [Format Plot Area]{.uicontrol}. The [Format Plot Area]{.uicontrol} task pane appears.
3. Open the [Fill]{.uicontrol} option and select [Solid fill]{.uicontrol} with a light gray color.
4. Open the [Border]{.uicontrol} option and select [Solid line]{.uicontrol} with a black color
{#fig-bakery-plotarea}
:::
## Adding and Removing Data Series {#sec-charts-data-source}
It's common to add a new data series to an existing chart or remove an old one. The procedure depends on whether the data to be added or removed is directly adjacent to the existing data set. You can easily determine this by selecting a chart; Excel will highlight the corresponding source data in the worksheet with colored boxes.
New series joins the highlighted area
: Expand the data range by dragging the selection.
: Delete a series at the beginning or end of the highlighted area by dragging.
New series does not join the highlighted area
: Use the ***Select data source*** dialog box.
Both techniques are covered in this section.
::: {#prp-charts-data-source1}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
**Add a new 2011 data series by dragging**
1. Open the file.
2. Add the new data for year 2011 in the range E1:E5, as shown in @fig-bakery-data-2011).
{#fig-bakery-data-2011}
3. Select the chart. The source data is selected on the worksheet, showing the sizing handles.
{#fig-bakery-data-marked}
4. Drag the lower-right sizing handle to include the new data.
{#fig-bakery-chart-2008-2011}
:::
::: {#prp-charts-data-source2}
**Delete the 2008 dataset by dragging**
1. Select the chart.
The source data is selected on the worksheet, showing the sizing handles.
{#fig-bakery-data2011-marked}
2. Drag the lower-left sizing handle to exclude the data for 2008.
{#fig-bakery-chart-2009-2011}
:::
:::: {#prp-charts-data-source3}
**Add the 2008 series and delete the 2011 series via the dialog box**
1. Right-click on the chart and choose [Select Data...]{.uicontrol}.
::: {.callout-tip title="Alternative method"}
An alternative is [Chart Design tab \> Select Data (Data group)]{.uicontrol}.
:::
{#fig-bakery-select-datasource}
2. Click the [Add]{.uicontrol} button.
{#fig-chart-edit-series}
- [Series name]{.uicontrol}: The cell that contains the name of the data series.
- [Series values]{.uicontrol}: The cell range that contains the data values.
3. Place the cursor in the [Series name]{.uicontrol} box and then select cell B1 in the worksheet.
4. Select the contents of the [Series values]{.uicontrol} box and then select the range B2:B5 in the worksheet.
5. Click [OK]{.uicontrol}.
The 2008 data series is added to the chart and the Select Data Source dialog box. However, it's added at the end, making the order illogical.
{#fig-bakery-datasource-moveup}
6. In the dialog box, select the [2008]{.uicontrol} series and click the [Move Up]{.uicontrol} arrow three times to make it the first series.
7. In the Select Data Source dialog box, select the [2011]{.uicontrol} series and click the [Remove]{.uicontrol} button.
The 2011 data series is removed, restoring the initial situation with the 2008-2010 data series.
::::
## Task: Changing Chart Type {#sec-charts-type-change}
You can easily change the chart type. This task demonstrates changing a column chart to a line chart.
::: {#prp-charts-type-change}
[File]{.smallcaps}: `Bakery_Chart.xlsx`
1. Open the file.
2. Select the chart.
3. Choose [Chart Design \> Change Chart Type (Type group)]{.uicontrol}.
{#fig-chart-type-change}
4. Choose the [Line with Markers]{.uicontrol} type and click [OK]{.uicontrol}.
{#fig-bakery-line}
:::
## Case Share Prices {#sec-charts-case}
[File]{.smallcaps}: `Stocks.xlsx`
@fig-case-data shows the average monthly share prices of four companies for January through March:
{#fig-case-data}
Create a line chart from this data.
Later, the entries for April are published:
{#fig-case-data-april}
Add this data to the chart.
The final result should look like this
{#fig-case-chart}
::: {.content-visible when-format="html:js"}
`r hide("Hint")`
- The chart type is a line chart (line with markers).
- When you create a chart, Excel might use the rows as data series instead of the columns. Correct this by switching rows/columns.
- Add a chart title. Format the title text in Palatino, 14 pt, bold.
- Add a vertical axis title.
- Scale the vertical axis so that the primary unit is 10.
- Add a legend below the horizontal axis and stretch the legend to display all texts in one row.
- Add horizontal dotted gridlines.
- Chart dimensions: width = 4" and height = 4"
`r unhide()`
:::
## Exercises {#sec-charts-exercises}
:::: {#exr-graf001}
**Third-degree chart (graf001)**
Create the following chart. Make the layout as similar as possible.

::: {.content-visible when-format="html:js"}
`r hide("Hint")`
First, create two columns in a worksheet with values for X and calculated values for Y. Create a scatter chart and apply the formatting.
`r unhide()`
:::
::::
::: {#exr-graf002}
**Travel bookings (graf002)**
[File]{.smallcaps}: `Graf002.xlsx`
The following table lists the travel booking data for the years 2008-2010.

Enter the data in a worksheet and use formulas for the totals. Then, create the following chart.

:::
::: {#exr-graf003}
**Sales figures (graf003)**
[File]{.smallcaps}: `Graf003.xlsx`
The following table shows the estimated and actual sales figures per quarter for 2010, as well as the difference between them. The average percentage of the differences is also calculated.

Enter the data in a worksheet and use formulas for the differences and the average. Then, create the following chart.

:::
::: {#exr-graf004}
**Age structure (graf004)**
[File]{.smallcaps}: `Graf004.xlsx`
The following table lists the percentages of the Dutch population's age structure for the years 1950-2010, divided into nine age classes (source: CBS).

Create the following chart from this data.

:::
:::: {#exr-graf005}
**Relationship between production time and cost (graf005)**
[File]{.smallcaps}:`Graf005.xlsx`
A toy manufacturing company suspects that the price of toys largely depends on production time. To investigate this, they measured the production time of the toys. The results and associated costs are shown in the following figure.

1. Create a chart that plots cost against production time (the independent variable).
2. Add a linear trend line to the chart, and include the trend line's equation.
::: {.content-visible when-format="html:js"}
`r hide("Answer")`

`r unhide()`
:::
::::
::: {#exr-graf006}
**Counting agarics (graf006)**
[File]{.smallcaps}: `Graf006.xlsx`
The number of agarics in a given area is counted annually. The following table shows the number of agarics per hectare for several years.

Create the following chart from this data.

:::