使用plot__y R软件包缩放点和选择颜色

使用plot__y R软件包缩放点和选择颜色,r,plotly,R,Plotly,我刚刚开始在R中使用plotly,它工作得很好,但我不知道如何做两件事 1) 我需要选择我的分裂的颜色。目前,我正在按地域划分,plotly不允许我对每个地域的颜色进行编码。 2) 我还需要缩放点,使一些标记非常大。我尝试为每行创建一个大小,并将size=~size和size=c(2100)设置为size=~size和size=c,但这不起作用 有什么建议吗?我已尝试阅读《plotly R参考指南》,但不知道如何使用plotly_mapbox执行此操作。我粘贴代码时没有尝试大小或颜色,因为我无法

我刚刚开始在R中使用plotly,它工作得很好,但我不知道如何做两件事

1) 我需要选择我的分裂的颜色。目前,我正在按地域划分,plotly不允许我对每个地域的颜色进行编码。 2) 我还需要缩放点,使一些标记非常大。我尝试为每行创建一个大小,并将size=~size和size=c(2100)设置为size=~size和size=c,但这不起作用

有什么建议吗?我已尝试阅读《plotly R参考指南》,但不知道如何使用plotly_mapbox执行此操作。我粘贴代码时没有尝试大小或颜色,因为我无法让它工作

p <- df %>%
  plot_mapbox(lat = ~lat, lon = ~lon,
              split = ~Territory, 
              mode = 'scattermapbox',
              text = df$text,
              hoverinfo = "text"
              ) %>%
  layout(title = 'Ship to Zip Codes',
         font = list(color='white'),
         plot_bgcolor = '#191A1A', 
         paper_bgcolor = '#191A1A',
         mapbox = list(style = 'dark'),
         legend = list(orientation = 'h',
                  font = list(size = 8)),
         margin = list(l = 25, r = 25,
                       b = 25, t = 25,
                       pad = 2))
p%
绘制地图盒(纬度=~纬度,经度=~经度,
斯普利特=~领土,
模式='scattermapbox',
text=df$text,
hoverinfo=“text”
) %>%
布局(标题=‘发货至邮政编码’,
font=list(color='white'),
plot_bgcolor='#191A1A',
纸张颜色='#191A1A',
映射框=列表(样式='暗'),
图例=列表(方向='h',
字体=列表(大小=8)),
边距=列表(l=25,r=25,
b=25,t=25,
pad=2)

您可以通过
marker=list(size=2)
设置标记大小

设置颜色更复杂,据我所知,无法直接使用
plot\u mapbox
完成


但我们可以为数据框指定一个新列

df$colors <- factor(df$class, levels = unique(df$class))

在Plotly中获取散点图中自定义颜色的全部代码

library(plotly)

df = read.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv')

df$colors <- factor(df$class, levels = unique(df$class))
cols <- c("red", "blue", "black", "green", "orange", "cyan", "gray50")

plot_geo(df) %>%
add_markers(x = ~reclong, 
            y = ~reclat, 
            color = ~df$colors, 
            colors = cols, 
            marker = list(size = 2))
library(plotly)
df=read.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv')
df$颜色
plot_geo(df) %>%
  add_markers(
    x = ~reclong, y = ~reclat, color = ~colors, colors = cols, marker = list(size = 2))
library(plotly)

df = read.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv')

df$colors <- factor(df$class, levels = unique(df$class))
cols <- c("red", "blue", "black", "green", "orange", "cyan", "gray50")

plot_geo(df) %>%
add_markers(x = ~reclong, 
            y = ~reclat, 
            color = ~df$colors, 
            colors = cols, 
            marker = list(size = 2))