我可以在地图上绘制圆形标记,如本例所示。但我想在add_markers中将标记形状从圆圈更改为正方形,但我无法在帮助(add_markers)或在线示例中找到解决方案。我试图添加type = list(“squares”)但不幸的是它没有改变任何东西。
require(plotly)
df<- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_ebola.csv')
# restrict from June to September
df <- subset(df, Month %in% 6:9)
# ordered factor variable with month abbreviations
df$abbrev <- ordered(month.abb[df$Month], levels = month.abb[6:9])
# September totals
df9 <- subset(df, Month == 9)
p <- df %>%
plot_geo(
locationmode = 'country names', sizes = c(1, 600), color = I("black")
) %>%
add_markers(
y = ~Lat, x = ~Lon, locations = ~Country,
size = ~Value, color = ~abbrev, text = ~paste(Value, "cases")
)
p
答案 0 :(得分:1)
有一个名为symbol
的参数。你可以使用
p <- df %>%
plot_geo(
locationmode = 'country names', sizes = c(1, 600), color = I("black")
) %>%
add_markers(
y = ~Lat, x = ~Lon, locations = ~Country,
size = ~Value, color = ~abbrev, text = ~paste(Value, "cases"),
symbol = ~abbrev
)
p
您也可以使用
指定符号p <- df %>%
plot_geo(
locationmode = 'country names', sizes = c(1, 600), color = I("black")
) %>%
add_markers(
y = ~Lat, x = ~Lon, locations = ~Country,
size = ~Value, color = ~abbrev, text = ~paste(Value, "cases"),
symbol = ~abbrev, symbols = c('circle', 'square', 'x', 'triangle')
)
p
如果您只想将圆圈切换为另一个符号,请使用:
p <- df %>%
plot_geo(
locationmode = 'country names', sizes = c(1, 600), color = I("black")
) %>%
add_markers(
y = ~Lat, x = ~Lon, locations = ~Country,
size = ~Value, color = ~abbrev, text = ~paste(Value, "cases"),
symbol = 'triangle'
)
p
希望它有所帮助。