简体   繁体   English

在 R 中修改图例中的标签 Plotly

[英]Modify labels in legend Plotly in R

I am trying to modify the labels in the legend of a scatterplot generated in Plotly for R. I am getting 0 and 1 labels.我正在尝试修改在 Plotly 中为 R 生成的散点图的图例中的标签。我得到了 0 和 1 标签。 I would like to modify them (0=Bad; 1=Good).我想修改它们(0=坏;1=好)。 Could you be so kind to help me modifying this legend?能不能帮我修改一下这个传说?

I am sharing with you a code that generates this legend and a picture of the chart.我正在与您分享生成此图例和图表图片的代码。

set.seed(1)
x<-rnorm(100)
set.seed(1)
y<-rnorm(100)
set.seed(1)
z<-rdunif(100, 0, 1)
newz<-as.factor(as.numeric(z)) 
scatter<-plot_ly(x = ~x, y = ~y, color = ~newz, type = "scatter", mode="markers")
scatter

Legend传奇

Recoding newz before or while creating the plot will modify the legend labels.在创建绘图之前或同时重新编码newz将修改图例标签。

Here are two ways of recoding while creating the plot:以下是在创建绘图时重新编码的两种方法:

# recode the color argument
scatter<-plot_ly(x = ~x, y = ~y, color = ifelse(newz == 0, "Bad", "Good"), 
                 type = "scatter", mode="markers") 

# recode the name argument 
scatter<-plot_ly(x = ~x, y = ~y, color = ~newz, type = "scatter", mode="markers",
                 name = ifelse(newz == 0, "Bad", "Good")) 

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM