我正在使用散点图,我想将公制CYI更改为绿色,将公制LYI更改为红色。
library(plotly)
dataset <- data.frame(SC = c("A","B","C","D"),
CYI = c(100,150,180,80),
LYI = c(80,120,190,90)
)
CYI_Text <- paste("Status Category = ", dataset$SC, "<br>",
"Current Year Interaction = ", dataset$CYI, "<br>")
LYI_Text <- paste("Status Category = ", dataset$SC, "<br>",
"Last Year Interaction = ", dataset$LYI, "<br>")
g <- plot_ly(dataset, x = dataset$SC, y = dataset$CYI, mode = 'markers' , marker = list(size =20) ) %>%
add_trace(x= dataset$SC, y = dataset$CYI , type = 'scatter', hoverinfo = "text", text = CYI_Text, color ="red", showlegend = FALSE) %>%
add_trace(x= dataset$SC, y = dataset$LYI , type = 'scatter', hoverinfo = "text", text = LYI_Text, color ="green", showlegend = TRUE)
g
任何帮助都会非常感激。