簡體   English   中英

重新定位 plotly 中的顏色條並更改色標 (R)

[英]Reposition colorbar in plotly and change color scale (R)

我正在使用 plotly 創建一個scattermapbox plotly並希望:

  1. 使顏色條水平並將 position 它放在我的 plot 的頂部
  2. 將色階更改為紅色陰影並將其重命名為“海拔”

我嘗試按照在線示例進行操作,但它不起作用:

  1. 我在layout中添加了legend = list(orientation = 'h') ,但沒有任何區別。 (這里的第二個例子: https://plotly.com/r/scattermapbox/
  2. https://plotly.com/r/scattermapbox/上的(第一個)示例之后將coloraxis = list(colorscale = "Reds")添加到layout中,但沒有成功
  3. 其他示例顯示可以通過將命名列表添加到marker來重命名顏色條 marker = list(..., colorbar marker = list(..., colorbar = list(title = 'My title')) 參考文檔中沒有名為colorbar的參數。 (此處示例: https://plotly.com/r/colorscales/

附帶說明一下,我有一個 mapbox 令牌,然而,plot 似乎只適用於少數 styles。

數據

從整個數據集中共享 50 個均勻分布的點(6000 個點):

structure(list(lat = c(45.547955, 45.549801, 45.551437, 45.554653, 
45.559059, 45.560158, 45.563854, 45.567379, 45.5715069, 45.575817, 
45.579056, 45.582672, 45.586857, 45.591194, 45.59362, 45.597103, 
45.601231, 45.605034, 45.608997, 45.611233, 45.615376, 45.61932, 
45.622749, 45.625629, 45.628456, 45.631489, 45.631611, 45.632305, 
45.630135, 45.626793, 45.623497, 45.620045, 45.615589, 45.610992, 
45.606541, 45.602821, 45.599106, 45.595169, 45.591198, 45.5872079, 
45.582672, 45.578587, 45.57476, 45.570515, 45.565872, 45.56226, 
45.55862, 45.555603, 45.552097, 45.548283), lon = c(-73.666939, 
-73.668861, -73.674332, -73.673698, -73.672272, -73.66761, -73.664688, 
-73.661179, -73.660103, -73.658028, -73.657333, -73.654381, -73.652786, 
-73.651154, -73.648354, -73.644836, -73.64328, -73.641556, -73.63961, 
-73.637321, -73.635498, -73.632965, -73.629128, -73.624321, -73.620491, 
-73.615967, -73.613396, -73.61422, -73.618103, -73.622635, -73.627571, 
-73.632332, -73.635414, -73.637466, -73.638702, -73.640244, -73.643547, 
-73.646996, -73.649826, -73.651886, -73.652626, -73.6558, -73.6588359, 
-73.660416, -73.662086, -73.665947, -73.668335, -73.671501, -73.666359, 
-73.667671), ele = c(30.2, 27, 26.6, 25.7999999, 23.2, 26.7999999, 
20, 24, 22.7999999, 20.6, 19, 22.2, 19.2, 17.3999999, 25.2, 25.2, 
17, 16.6, 15.3999999, 17, 15.2, 15.6, 16.3999999, 16.7999999, 
17.7999999, 17.6, 24.3999999, 18.2, 18.6, 18.6, 19.2, 17, 17.2, 
18.7999999, 23.7999999, 27.7999999, 27.7999999, 26, 30.7999999, 
27.2, 29.2, 24, 23.7999999, 26.6, 24.7999999, 26.2, 31, 31, 31.2, 
32.6)), row.names = c(NA, -50L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x7fb33c8118e0>)

代碼

plt <- plot_mapbox(data = track, mode = 'scattermapbox',
                   lat = ~lat, lon = ~lon, color = ~ele) %>% 
  layout(mapbox = list(style = 'carto-positron', zoom = 10, # open-street-map works, but light, dark, basic don't work 
                  center = list(lon = track[, mean(lon)], lat = track[, mean(lat)])), 
    margin = list(l = 0, r = 0, t = 0, b = 0), 
    legend = list(orientation = 'h'))

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM