Skip to contents

These functions are helper functions for working with segment data as keys in guides. They all share the goal of creating a guide key, but have different methods:

  • key_segment_manual() directly uses user-provided vectors to set segments.

  • key_segment_map() makes mappings from a <data.frame> to set segments.

  • key_dendro() is a specialty case for coercing dendrogram data to segments. Be aware that setting the key alone cannot affect the scale limits, and will give misleading results when used incorrectly!

Usage

key_segment_manual(value, oppo, value_end = value, oppo_end = oppo, ...)

key_segment_map(data, ..., .call = caller_env())

key_dendro(dendro = NULL, type = "rectangle", ..., .call = NULL)

Arguments

value, value_end

A vector that is interpreted to be along the scale that the guide codifies.

oppo, oppo_end

A vector that is interpreted to be orthogonal to the value and value_end variables.

...

The ... parameter has two purposes.

  1. In key_segments_map() it is <data-masking>. A set of mappings similar to those provided to aes(), which will be evaluated in the data argument. These must contain value and oppo mappings.

  2. In other keys, ... can be used to transfer graphical properties to the individual breaks of a guide. For example, using colour = "blue" will draw parts of the guides associated with breaks in blue. There is a shallow hierarchy in that line_colour is the specific property for segment elements, but others inherit from the main colour setting. Likewise, linewidth and linetype have specific variants for line elements.

data

A <data.frame> or similar object coerced by fortify() to a <data.frame>, in which the mapping argument is evaluated.

.call

A call to display in messages.

dendro

A data structure that can be coerced to a dendrogram through the as.dendrogram() function. When NULL (default) an attempt is made to search for such data in the scale.

type

A string, either "rectangle" or "triangle", indicating the shape of edges between nodes of the dendrogram.

Value

For key_segments_manual() and key_segments_map(), a <data.frame> with the <key_range> class.

See also

Examples

# Giving vectors directly
key_segment_manual(
  value = 0:1, value_end = 2:3,
  oppo  = 1:0, oppo_end  = 3:2
)
#>   value oppo value_end oppo_end
#> 1     0    1         2        3
#> 2     1    0         3        2

# Taking columns of a data frame
data <- data.frame(x = 0:1, y = 1:0, xend = 2:3, yend = 3:2)
key_segment_map(data, value = x, oppo = y, value_end = xend, oppo_end = yend)
#>   value oppo value_end oppo_end
#> 1     0    1         2        3
#> 2     1    0         3        2

# Using dendrogram data
clust <- hclust(dist(USArrests), "ave")
key_dendro(clust)(scale_x_discrete())
#>         value       oppo value_end   oppo_end
#> 1   17.994141 152.313999  4.765625 152.313999
#> 2    4.765625 152.313999  4.765625  77.605024
#> 3   17.994141 152.313999 31.222656 152.313999
#> 4   31.222656 152.313999 31.222656  89.232093
#> 5    4.765625  77.605024  1.500000  77.605024
#> 6    1.500000  77.605024  1.500000  38.527912
#> 7    4.765625  77.605024  8.031250  77.605024
#> 8    8.031250  77.605024  8.031250  44.283922
#> 9    1.500000  38.527912  1.000000  38.527912
#> 10   1.000000  38.527912  1.000000   0.000000
#> 11   1.500000  38.527912  2.000000  38.527912
#> 12   2.000000  38.527912  2.000000   0.000000
#> 13   8.031250  44.283922  3.875000  44.283922
#> 14   3.875000  44.283922  3.875000  28.012211
#> 15   8.031250  44.283922 12.187500  44.283922
#> 16  12.187500  44.283922 12.187500  39.394633
#> 17   3.875000  28.012211  3.000000  28.012211
#> 18   3.000000  28.012211  3.000000   0.000000
#> 19   3.875000  28.012211  4.750000  28.012211
#> 20   4.750000  28.012211  4.750000  15.453120
#> 21   4.750000  15.453120  4.000000  15.453120
#> 22   4.000000  15.453120  4.000000   0.000000
#> 23   4.750000  15.453120  5.500000  15.453120
#> 24   5.500000  15.453120  5.500000  13.896043
#> 25   5.500000  13.896043  5.000000  13.896043
#> 26   5.000000  13.896043  5.000000   0.000000
#> 27   5.500000  13.896043  6.000000  13.896043
#> 28   6.000000  13.896043  6.000000   0.000000
#> 29  12.187500  39.394633  9.625000  39.394633
#> 30   9.625000  39.394633  9.625000  26.363428
#> 31  12.187500  39.394633 14.750000  39.394633
#> 32  14.750000  39.394633 14.750000  28.095803
#> 33   9.625000  26.363428  7.750000  26.363428
#> 34   7.750000  26.363428  7.750000  16.891499
#> 35   9.625000  26.363428 11.500000  26.363428
#> 36  11.500000  26.363428 11.500000  18.417331
#> 37   7.750000  16.891499  7.000000  16.891499
#> 38   7.000000  16.891499  7.000000   0.000000
#> 39   7.750000  16.891499  8.500000  16.891499
#> 40   8.500000  16.891499  8.500000  15.454449
#> 41   8.500000  15.454449  8.000000  15.454449
#> 42   8.000000  15.454449  8.000000   0.000000
#> 43   8.500000  15.454449  9.000000  15.454449
#> 44   9.000000  15.454449  9.000000   0.000000
#> 45  11.500000  18.417331 10.500000  18.417331
#> 46  10.500000  18.417331 10.500000   6.236986
#> 47  11.500000  18.417331 12.500000  18.417331
#> 48  12.500000  18.417331 12.500000  13.297368
#> 49  10.500000   6.236986 10.000000   6.236986
#> 50  10.000000   6.236986 10.000000   0.000000
#> 51  10.500000   6.236986 11.000000   6.236986
#> 52  11.000000   6.236986 11.000000   0.000000
#> 53  12.500000  13.297368 12.000000  13.297368
#> 54  12.000000  13.297368 12.000000   0.000000
#> 55  12.500000  13.297368 13.000000  13.297368
#> 56  13.000000  13.297368 13.000000   0.000000
#> 57  14.750000  28.095803 14.000000  28.095803
#> 58  14.000000  28.095803 14.000000   0.000000
#> 59  14.750000  28.095803 15.500000  28.095803
#> 60  15.500000  28.095803 15.500000  21.167192
#> 61  15.500000  21.167192 15.000000  21.167192
#> 62  15.000000  21.167192 15.000000   0.000000
#> 63  15.500000  21.167192 16.000000  21.167192
#> 64  16.000000  21.167192 16.000000   0.000000
#> 65  31.222656  89.232093 23.796875  89.232093
#> 66  23.796875  89.232093 23.796875  44.837933
#> 67  31.222656  89.232093 38.648438  89.232093
#> 68  38.648438  89.232093 38.648438  54.746831
#> 69  23.796875  44.837933 20.343750  44.837933
#> 70  20.343750  44.837933 20.343750  26.713777
#> 71  23.796875  44.837933 27.250000  44.837933
#> 72  27.250000  44.837933 27.250000  29.054195
#> 73  20.343750  26.713777 17.937500  26.713777
#> 74  17.937500  26.713777 17.937500  16.425489
#> 75  20.343750  26.713777 22.750000  26.713777
#> 76  22.750000  26.713777 22.750000  22.595978
#> 77  17.937500  16.425489 17.000000  16.425489
#> 78  17.000000  16.425489 17.000000   0.000000
#> 79  17.937500  16.425489 18.875000  16.425489
#> 80  18.875000  16.425489 18.875000  12.878100
#> 81  18.875000  12.878100 18.000000  12.878100
#> 82  18.000000  12.878100 18.000000   0.000000
#> 83  18.875000  12.878100 19.750000  12.878100
#> 84  19.750000  12.878100 19.750000  10.736739
#> 85  19.750000  10.736739 19.000000  10.736739
#> 86  19.000000  10.736739 19.000000   0.000000
#> 87  19.750000  10.736739 20.500000  10.736739
#> 88  20.500000  10.736739 20.500000   7.355270
#> 89  20.500000   7.355270 20.000000   7.355270
#> 90  20.000000   7.355270 20.000000   0.000000
#> 91  20.500000   7.355270 21.000000   7.355270
#> 92  21.000000   7.355270 21.000000   0.000000
#> 93  22.750000  22.595978 22.000000  22.595978
#> 94  22.000000  22.595978 22.000000   0.000000
#> 95  22.750000  22.595978 23.500000  22.595978
#> 96  23.500000  22.595978 23.500000  11.456439
#> 97  23.500000  11.456439 23.000000  11.456439
#> 98  23.000000  11.456439 23.000000   0.000000
#> 99  23.500000  11.456439 24.000000  11.456439
#> 100 24.000000  11.456439 24.000000   0.000000
#> 101 27.250000  29.054195 25.750000  29.054195
#> 102 25.750000  29.054195 25.750000  20.198479
#> 103 27.250000  29.054195 28.750000  29.054195
#> 104 28.750000  29.054195 28.750000  23.972143
#> 105 25.750000  20.198479 25.000000  20.198479
#> 106 25.000000  20.198479 25.000000   0.000000
#> 107 25.750000  20.198479 26.500000  20.198479
#> 108 26.500000  20.198479 26.500000  12.614278
#> 109 26.500000  12.614278 26.000000  12.614278
#> 110 26.000000  12.614278 26.000000   0.000000
#> 111 26.500000  12.614278 27.000000  12.614278
#> 112 27.000000  12.614278 27.000000   0.000000
#> 113 28.750000  23.972143 28.000000  23.972143
#> 114 28.000000  23.972143 28.000000   0.000000
#> 115 28.750000  23.972143 29.500000  23.972143
#> 116 29.500000  23.972143 29.500000  14.501034
#> 117 29.500000  14.501034 29.000000  14.501034
#> 118 29.000000  14.501034 29.000000   0.000000
#> 119 29.500000  14.501034 30.000000  14.501034
#> 120 30.000000  14.501034 30.000000   0.000000
#> 121 38.648438  54.746831 34.437500  54.746831
#> 122 34.437500  54.746831 34.437500  20.598507
#> 123 38.648438  54.746831 42.859375  54.746831
#> 124 42.859375  54.746831 42.859375  41.094765
#> 125 34.437500  20.598507 31.875000  20.598507
#> 126 31.875000  20.598507 31.875000  15.026107
#> 127 34.437500  20.598507 37.000000  20.598507
#> 128 37.000000  20.598507 37.000000  15.122897
#> 129 31.875000  15.026107 31.000000  15.026107
#> 130 31.000000  15.026107 31.000000   0.000000
#> 131 31.875000  15.026107 32.750000  15.026107
#> 132 32.750000  15.026107 32.750000  12.438692
#> 133 32.750000  12.438692 32.000000  12.438692
#> 134 32.000000  12.438692 32.000000   0.000000
#> 135 32.750000  12.438692 33.500000  12.438692
#> 136 33.500000  12.438692 33.500000   3.834058
#> 137 33.500000   3.834058 33.000000   3.834058
#> 138 33.000000   3.834058 33.000000   0.000000
#> 139 33.500000   3.834058 34.000000   3.834058
#> 140 34.000000   3.834058 34.000000   0.000000
#> 141 37.000000  15.122897 35.500000  15.122897
#> 142 35.500000  15.122897 35.500000   6.637771
#> 143 37.000000  15.122897 38.500000  15.122897
#> 144 38.500000  15.122897 38.500000  13.352260
#> 145 35.500000   6.637771 35.000000   6.637771
#> 146 35.000000   6.637771 35.000000   0.000000
#> 147 35.500000   6.637771 36.000000   6.637771
#> 148 36.000000   6.637771 36.000000   0.000000
#> 149 38.500000  13.352260 37.500000  13.352260
#> 150 37.500000  13.352260 37.500000   3.929377
#> 151 38.500000  13.352260 39.500000  13.352260
#> 152 39.500000  13.352260 39.500000   8.027453
#> 153 37.500000   3.929377 37.000000   3.929377
#> 154 37.000000   3.929377 37.000000   0.000000
#> 155 37.500000   3.929377 38.000000   3.929377
#> 156 38.000000   3.929377 38.000000   0.000000
#> 157 39.500000   8.027453 39.000000   8.027453
#> 158 39.000000   8.027453 39.000000   0.000000
#> 159 39.500000   8.027453 40.000000   8.027453
#> 160 40.000000   8.027453 40.000000   0.000000
#> 161 42.859375  41.094765 41.000000  41.094765
#> 162 41.000000  41.094765 41.000000   0.000000
#> 163 42.859375  41.094765 44.718750  41.094765
#> 164 44.718750  41.094765 44.718750  33.117815
#> 165 44.718750  33.117815 42.750000  33.117815
#> 166 42.750000  33.117815 42.750000  10.771175
#> 167 44.718750  33.117815 46.687500  33.117815
#> 168 46.687500  33.117815 46.687500  27.779904
#> 169 42.750000  10.771175 42.000000  10.771175
#> 170 42.000000  10.771175 42.000000   0.000000
#> 171 42.750000  10.771175 43.500000  10.771175
#> 172 43.500000  10.771175 43.500000   8.537564
#> 173 43.500000   8.537564 43.000000   8.537564
#> 174 43.000000   8.537564 43.000000   0.000000
#> 175 43.500000   8.537564 44.000000   8.537564
#> 176 44.000000   8.537564 44.000000   0.000000
#> 177 46.687500  27.779904 45.500000  27.779904
#> 178 45.500000  27.779904 45.500000  13.044922
#> 179 46.687500  27.779904 47.875000  27.779904
#> 180 47.875000  27.779904 47.875000  18.993398
#> 181 45.500000  13.044922 45.000000  13.044922
#> 182 45.000000  13.044922 45.000000   0.000000
#> 183 45.500000  13.044922 46.000000  13.044922
#> 184 46.000000  13.044922 46.000000   0.000000
#> 185 47.875000  18.993398 47.000000  18.993398
#> 186 47.000000  18.993398 47.000000   0.000000
#> 187 47.875000  18.993398 48.750000  18.993398
#> 188 48.750000  18.993398 48.750000  10.184218
#> 189 48.750000  10.184218 48.000000  10.184218
#> 190 48.000000  10.184218 48.000000   0.000000
#> 191 48.750000  10.184218 49.500000  10.184218
#> 192 49.500000  10.184218 49.500000   2.291288
#> 193 49.500000   2.291288 49.000000   2.291288
#> 194 49.000000   2.291288 49.000000   0.000000
#> 195 49.500000   2.291288 50.000000   2.291288
#> 196 50.000000   2.291288 50.000000   0.000000