2017-01-19 25 views
1

2つの米国状態マップをプロットするのが理想的ですが、同じカラースケールを持つデータフレームがあります。あなたが見ることができるように例えば1.6の値は両方のマップ私は2つのマップに同じ色の罫線をプロットしてプロットすることができます。

library(plotly) 
library(tidyverse) 

df <- structure(list(stateID = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
46L, 47L, 48L, 49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 
48L, 49L, 50L, 51L), .Label = c("AK", "AL", "AR", "AZ", "CA", 
"CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", 
"KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", 
"NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", 
"PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", 
"WV", "WY"), class = "factor"), category = structure(c(1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L), .Label = c("small", "large"), class = "factor"), 
values = c(1.49852796690539, 1.149561395403, 1.24566150736064, 
1.00189715065062, 0.987562097609043, 0.231859257910401, 1.64033870631829, 
0.12613168777898, 1.91596280829981, 1.35835290746763, 0.792609711177647, 
1.97339694341645, 0.376533678267151, 1.63516522897407, 0.225585919804871, 
0.505839260760695, 0.0116439824923873, 1.51879569422454, 
1.35506999026984, 0.907982874661684, 1.08905055327341, 1.43553646048531, 
1.88463490083814, 0.908853257540613, 0.902149567846209, 1.5428032441996, 
1.62871437706053, 0.623223986010998, 1.38058050535619, 1.57016781903803, 
1.8731079204008, 0.297486190218478, 1.27625703299418, 0.519723014440387, 
0.848097313195467, 0.471342021599412, 1.98357644258067, 1.82963251601905, 
0.626917572226375, 0.140670910011977, 1.1393640646711, 1.99097026558593, 
1.70624398859218, 0.0956417261622846, 1.53923089429736, 1.25705669261515, 
1.89643088867888, 1.88176721381024, 1.44151636445895, 0.435520166531205, 
1.18845809064806, 2.95685278996825, 1.37898187059909, 2.95418810285628, 
1.94776474731043, 1.98949646670371, 1.37768995529041, 2.0124197602272, 
1.33321205340326, 2.07528439210728, 2.49668326042593, 2.69146995106712, 
1.52930808160454, 1.90695044351742, 1.74849874572828, 2.3098370959051, 
1.59070889744908, 1.52278333622962, 2.13915946660563, 1.52873482694849, 
1.39334590546787, 1.82181124016643, 2.44108150294051, 2.21637984598055, 
1.99761381838471, 2.33465715777129, 2.53672145865858, 2.98815744556487, 
1.09659902472049, 1.13088199263439, 1.91391275310889, 1.07779059326276, 
1.03311925474554, 1.25638853525743, 2.84107198892161, 2.64419505093247, 
1.85066655138507, 2.65426727430895, 2.37351916264743, 1.45171522675082, 
2.54493401898071, 1.40593391284347, 1.82211668742821, 1.36818132549524, 
2.88858095230535, 2.54271147632971, 2.90091867512092, 1.5358378039673, 
2.86527143837884, 2.71315307915211, 2.09380666306242, 2.02881665108725 
)), .Names = c("stateID", "category", "values"), row.names = c(NA, 
102L), class = "data.frame") 

small <-df %>% 
filter(category=="small") %>% 
plot_geo(locationmode = 'USA-states') %>% 
add_trace(
z = ~values, color = ~values, colors = "Blues", 
locations = ~stateID) %>% 
layout(geo=list(scope='usa')) 
small 

large <-df %>% 
filter(category=="large") %>% 
plot_geo(locationmode = 'USA-states') %>% 
add_trace(
z = ~values, color = ~values, colors = "Blues", 
locations = ~stateID) %>% 
layout(geo=list(scope='usa')) 
large 

small values

enter image description here

に同じ色を持つことになり、同じカラースケールは、各マップに異なる値をカバーしています。私は範囲0-3の単一のカラースケールが欲しいです。シーケンシャルオプション

TIA

答えて

1

あなたは各プロットで同じ値にzminzmaxを設定することにより、各マップの同じスケールを設定することができますしたいと思いますけれども、私は色の再口うるさいないです。それはdocumented in the helpですが、それは少しわかりにくいです: "zmax(数値):カラードメインの上限を設定します"(同様にzminの場合)

small <-df %>% 
    filter(category=="small") %>% 
    plot_geo(locationmode = 'USA-states') %>% 
    add_trace(
    z = ~values, color = ~values, colors = "Blues", 
    zmin=0, zmax=3, 
    locations = ~stateID) %>% 
    layout(geo=list(scope='usa'), title="Small") 

large <-df %>% 
    filter(category=="large") %>% 
    plot_geo(locationmode = 'USA-states') %>% 
    add_trace(
    z = ~values, color = ~values, colors = "Blues", 
    zmin=0, zmax=3, 
    locations = ~stateID) %>% 
    layout(geo=list(scope='usa'), title="Large") 

enter image description here

enter image description here

+0

おかげで多くを、V。はい、私は参考文献が圧倒的であると思います! – pssguy

関連する問題