设置标记大小 [英] Set marker size in plotly
问题描述
如何在地图上的R中以绘图方式更改标记大小?如果我将size
参数设置为任何数字,则会使其大小相同,太大.而且,如果我将其映射到数据中的变量,则标记很小,因此实际上一开始就可以分辨出差异.理想情况下,我想增加基本大小并通过映射到变量来保持比例.
How can I change the marker size in plotly in R on a map? If I set the size
argument to any number it makes it the same, too big size. And if I map it to a variable in my data, the markers are to small to really be able to tell the difference in the first place. Ideally I would like to increase the base size and keep the proportional aspect through mapping to the variable.
可复制的示例:
library(data.table)
library(plotly)
library(dplyr)
sample <- data.table(Region=c("Illinois","Illinois","California","California","Texas","Texas"),
code=c("IL","IL","CA","CA","TX","TX"),
Group=c("A","B"),
Value=rnorm(6, mean=100, sd=6))
sample[Region=="Illinois", c('lat', 'long') := list(40.3363, -89.0022)]
sample[Region=="California", c('lat', 'long') := list(36.17, -119.7462)]
sample[Region=="Texas", c('lat', 'long') := list(31.106, -97.6475)]
x <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = F,
lakecolor = toRGB('lightblue')
)
sample %>%
plot_geo(
locationmode='USA-states'
) %>%
add_markers(
y=~lat, x=~long, hoverinfo="text",
color=~Group,
text=~Group, size=~Value
) %>%
layout(
title='plotly marker map',
geo=x
)
推荐答案
最简单且可能是规范的方法是使用marker.sizeref
属性.您可以像这样将其包裹在marker=list(...)
内
The simplest, and probably canonical way is to use the marker.sizeref
attribute. You wrap this inside marker=list(...)
like this
plot_geo(sample, locationmode='USA-states') %>%
add_markers(y=~lat, x=~long, hoverinfo="text",
color=~Group, text=~Group, size=~Value,
marker=list(sizeref=0.1, sizemode="area")) %>%
layout(title='plotly marker map', geo=x)
请注意,sizeref
越小,标记越大.例如,通过sizeref=0.02
我们得到
Note that, the smaller sizeref
, the bigger the markers. E.g with sizeref=0.02
we get
这篇关于设置标记大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!