【问题标题】:Plotly: different symbols on scatterplotsPlotly:散点图上的不同符号
【发布时间】:2021-10-31 02:04:40
【问题描述】:
library(dplyr)
library(plotly)
library(plyr)

df <- data.frame(
    Category = c('foo', 'bar', 'bar', 'foo'),
    x = c(2.1, 3.4, 4, 4),
    y = c(16, 21, 10, 17)
)

palette <- c("#007700", "#cc0000")
fig <- plot_ly(data = df, x = ~x, y = ~y, size = 10, color = ~Category,
               colors = palette)
fig

如何将foo 点绘制为正方形,将bar 点绘制为三角形?

【问题讨论】:

    标签: r plotly scatter-plot


    【解决方案1】:

    添加symbol=~Category并定义symbols=

    plotly::plot_ly(
      data = df, x = ~x, y = ~y, size = 10, color = ~Category, colors = palette,
      symbol = ~Category, symbols = c(15, 17)
    )
    

    【讨论】:

    • 谢谢。你知道所有预制符号的列表在哪里吗? (15 = 实心正方形,17 = 实心三角形等)
    • 老实说,每次我不记得它们时,我都会查找它:google.com/search?q="r"+"plot"+"pch"。(Plotly 接受基本的 R 符号。)
    猜你喜欢
    • 2021-01-11
    • 2021-11-04
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多