在R中删除双图例
Posted
技术标签:
【中文标题】在R中删除双图例【英文标题】:Remove double legend plotly in R 【发布时间】:2021-12-07 03:21:43 【问题描述】:我不知道为什么我有一个双重传奇。
第二个图例怎么去掉Aa
代码:
city = c("paris", "lyon", "lyon", "marseille", "lille", "toulouse", "bordeaux")
start = c("2018-08-04", "2018-07-25", "2018-07-30", "2018-07-29", "2018-08-03", "2018-08-04", "2018-08-03")
max = c(36.4, 37.2, 38.4, 37.4, 36.7, 34.9, 34.8)
duration = c(4, 3, 8, 10, 5, 4, 3)
tab = data.frame(city, start, duration, max)
tab$duration = as.integer(tab$duration)
t <- list(
family = "sans serif",
size = 14,
color = toRGB("grey50"))
bubbleplot <- plot_ly(tab, x = ~start, y = ~max,
text = ~paste(duration, "jours"),
color = ~city, mode='markers+text'
)
bubbleplot = bubbleplot %>% add_markers(
marker = list(size = ~duration*4, opacity = 0.7,
sizemode = "diameter"))
bubbleplot <- bubbleplot %>% add_text(textfont = t, textposition = "inside")
bubbleplot
【问题讨论】:
Same question on plotly community forum: "请注意,在即将发布的 v2 库中,此 Aa 文本将不再出现在图例中" 【参考方案1】:使用以下,
t <- list(
family = "sans serif",
size = 14,
color = toRGB("grey50"))
bubbleplot <- plot_ly(tab, x = ~start, y = ~max,
text = ~paste(duration, "jours"),
color = ~city, mode='markers+text'
)
bubbleplot = bubbleplot %>% add_markers(
marker = list(size = ~duration*4, opacity = 0.7,
sizemode = "diameter")) %>% add_text(x = ~start, y = ~max,
text = ~paste(duration, "jours"), textfont = t, textposition = "inside", data = tab, inherit = F)
bubbleplot
【讨论】:
当我执行你的代码时,我没有气泡中的文本。 修改了答案,但你会得到一个文本图例以上是关于在R中删除双图例的主要内容,如果未能解决你的问题,请参考以下文章
R语言ggplot2可视化:去除可视化结果中的NA图例删除缺失值图例
R语言使用latticeExtra包可视化双Y轴线图实战(Dual Y axis):单y轴线图双y轴图线图双y轴图线图(添加图例)