[英]Modify labels in legend Plotly in R
我正在嘗試修改在 Plotly 中為 R 生成的散點圖的圖例中的標簽。我得到了 0 和 1 標簽。 我想修改它們(0=壞;1=好)。 能不能幫我修改一下這個傳說?
我正在與您分享生成此圖例和圖表圖片的代碼。
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
在創建繪圖之前或同時重新編碼newz
將修改圖例標簽。
以下是在創建繪圖時重新編碼的兩種方法:
# 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.