You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Choosing The Algorithm For Computing Quartiles
30
+
31
+
By default, quartiles for box plots are computed using the **linear** method (for more about linear interpolation, see #10 listed on http://www.amstat.org/publications/jse/v14n3/langford.html and https://en.wikipedia.org/wiki/Quartile for more details).
32
+
33
+
However, you can also choose to use an exclusive or an inclusive algorithm to compute quartiles.
34
+
35
+
The **exclusive** algorithm uses the median to divide the ordered dataset into two halves. If the sample is odd, it does not include the median in either half. Q1 is then the median of the lower half and Q3 is the median of the upper half.
36
+
37
+
The **inclusive** algorithm also uses the median to divide the ordered dataset into two halves, but if the sample is odd, it includes the median in both halves. Q1 is then the median of the lower half and Q3 the median of the upper half.
38
+
39
+
```{r}
40
+
library(plotly)
41
+
fig <- plot_ly(y = list(1,2,3,4,5), type = "box", quartilemethod="exclusive") # or "inclusive", or "linear" by default
42
+
43
+
fig
44
+
```
45
+
46
+
### Modifying The Algorithm For Computing Quartiles
47
+
48
+
For an explanation of how each algorithm works, see [Choosing The Algorithm For Computing Quartiles](https://plotly.com/r/box-plots/#choosing-the-algorithm-for-computing-quartiles)
A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a map composed of colored polygons. It is used to represent spatial variations of a quantity. This page documents how to build **outline** choropleth maps, but you can also build [choropleth **tile maps** using our Mapbox trace types](/r/mapbox-county-choropleth).
22
+
23
+
### Base Map Configuration
24
+
25
+
Plotly figures made with `plot_ly` have a `layout.geo` object which can be used to control the appearance of the base map onto which data is plotted.
26
+
27
+
### Introduction: main parameters for choropleth outline maps
28
+
29
+
Making choropleth maps requires two main types of input:
30
+
31
+
1. Geometry information:
32
+
1. This can either be a supplied GeoJSON file where each feature has either an `id` field or some identifying value in `properties`; or
33
+
2. one of the built-in geometries within `plot_ly`: US states and world countries (see below)
34
+
2. A list of values indexed by feature identifier.
35
+
36
+
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `z` argument of choropleth traces.
37
+
38
+
**Note** the `geojson` attribute can also be the URL to a GeoJSON file, which can speed up map rendering in certain cases.
39
+
40
+
### GeoJSON with `feature.id`
41
+
42
+
Here we load a GeoJSON file containing the geometry information for US counties, where `feature.id` is a [FIPS code](https://en.wikipedia.org/wiki/FIPS_county_code).
43
+
44
+
```{r}
45
+
library(plotly)
46
+
library(rjson)
47
+
48
+
data <- fromJSON(file="https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json")
49
+
data$features[[1]]
50
+
```
51
+
52
+
#### Data indexed by `id`
53
+
54
+
Here we load unemployment data by county, also indexed by [FIPS code](https://en.wikipedia.org/wiki/FIPS_county_code).
**Note** In this example we set `layout.geo.scope` to usa to automatically configure the map to display USA-centric data in an appropriate projection.
101
+
102
+
### Indexing by GeoJSON Properties
103
+
104
+
If the GeoJSON you are using either does not have an `id` field or you wish you use one of the keys in the `properties` field, you may use the `featureidkey` parameter to specify where to match the values of locations.
105
+
106
+
In the following GeoJSON object/data-file pairing, the values of `properties.district` match the values of the `district` column:
Plotly comes with two built-in geometries which do not require an external GeoJSON file:
141
+
142
+
1. USA States
143
+
2. Countries as defined in the Natural Earth dataset.
144
+
145
+
**Note and disclaimer:** cultural (as opposed to physical) features are by definition subject to change, debate and dispute. Plotly includes data from Natural Earth "as-is" and defers to the [Natural Earth policy regarding disputed borders](https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/) which read:
146
+
147
+
> Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground.
148
+
149
+
To use the built-in countries geometry, provide `locations` as [three-letter ISO country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3).
**Note** In this example we set `layout.geo.scope` to `usa` to automatically configure the map to display USA-centric data in an appropriate projection.
Copy file name to clipboardExpand all lines: r/2020-01-30-choropleth-rmapbox.Rmd
+39-3Lines changed: 39 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ description: How to make a Mapbox Choropleth Map of US Counties in R with Plotly
3
3
display_as: maps
4
4
language: r
5
5
layout: base
6
-
name: Choropleth mapbox
6
+
name: Mapbox Choropleth Maps
7
7
order: 8
8
8
output:
9
9
html_document:
@@ -33,7 +33,7 @@ Making choropleth Mapbox maps requires two main types of input:
33
33
1. GeoJSON-formatted geometry information where each feature has either an `id` field or some identifying value in `properties`.
34
34
2. A list of values indexed by feature identifier.
35
35
36
-
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `color` argument of `px.choropleth_mapbox` (`z` if using `graph_objects`), in the same order as the IDs are passed into the `location` argument.
36
+
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `z` argument of `plot_geo`.
37
37
38
38
**Note** the `geojson` attribute can also be the URL to a GeoJSON file, which can speed up map rendering in certain cases.
39
39
@@ -56,7 +56,7 @@ Here we load unemployment data by county, also indexed by [FIPS code](https://en
### Choropleth map using carto base map (no token needed)
59
+
### Mapbox Choropleth Map Using GeoJSON
60
60
61
61
With `choroplethmapbox`, each row of the DataFrame is represented as a region of the choropleth.
62
62
@@ -90,6 +90,42 @@ fig <- fig %>% layout(
90
90
)
91
91
fig
92
92
```
93
+
94
+
### Mapbox Choropleth Map Using GeoJSON with `featureidkey`
95
+
If the GeoJSON you are using either does not have an `id` field or you wish you use one of the keys in the `properties` field, you may use the `featureidkey` parameter to specify where to match the values of locations.
96
+
97
+
In the following GeoJSON object/data-file pairing, the values of `properties.district` match the values of the `district` column:
Copy file name to clipboardExpand all lines: r/2020-02-25-images.Rmd
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
name: Imshow
2
+
name: Display Image Data
3
3
description: How to display image data in Python with R.
4
4
display_as: scientific
5
5
layout: base
@@ -8,7 +8,8 @@ order: 15
8
8
output:
9
9
html_document:
10
10
keep_md: true
11
-
permalink: r/imshow/
11
+
permalink: r/displaying-images/
12
+
redirect_from: r/imshow/
12
13
thumbnail: thumbnail/imshow.jpg
13
14
---
14
15
@@ -22,6 +23,7 @@ This tutorial shows how to display and explore image data. If you would like ins
22
23
Note that `Image` trace only accepts multichannel images. For single images, use [`Heatmap`](https://plotly.com/r/heatmaps/). `Image` trace is different from the `layout.Image` class, which can be used for adding background images or logos to figures.
0 commit comments