【问题标题】:R scatter plot - different colors for text and markersR散点图 - 文本和标记的不同颜色
【发布时间】:2018-07-31 19:01:50
【问题描述】:

我有这样的问题 - 我想制作标记具有不同颜色的散点图。但问题在于标记的名称——它有不同于点的颜色。

有什么办法让它保持一致吗?

这里是代码示例:

library(data.table)
library(plotly)

data<-data.table(c('A','B','C'),c(1,2,3),c(3,2,1))

plot_ly(data,x=data$V2, y=data$V3,type='scatter',marker=list(size=10)) %>%
add_text(text=data$V1,textposition = "top right",color=data$V1) %>%
layout(showlegend = FALSE)

【问题讨论】:

    标签: r r-plotly


    【解决方案1】:

    试试这个。根据需要更改 t 中的内容。

    library(data.table)
    library(plotly)
    
    data<-data.table(c('A','B','C'),c(1,2,3),c(3,2,1))
    
    t <- list(
              family = "sans serif",
              size = 14,
              color = toRGB("grey50"))
    
    plot_ly(data,x=data$V2, y=data$V3,type='scatter',marker=list(size=10)) %>%
    add_text(textfont = t, text=data$V1,textposition = "top right",color=data$V1) %>%
    layout(showlegend = FALSE)   
    

    【讨论】:

    • 这里所有的文字都有相同的颜色。以及如何使每个标记和文本具有相同的颜色?
    猜你喜欢
    • 1970-01-01
    • 2020-05-16
    • 2014-12-16
    • 1970-01-01
    • 2021-07-13
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多