基于R中的度量的度量的散点图颜色

时间:2018-04-13 17:06:04

标签: r plotly

我正在使用散点图,我想将公制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

任何帮助都会非常感激。

0 个答案:

没有答案