【问题标题】:R ggplot + ggplotly: color scale doesn't workR ggplot + ggplotly:色标不起作用
【发布时间】:2020-07-10 07:28:08
【问题描述】:

从 ggplotly 开始,我似乎无法弄清楚如何使用色标。这是我得到的:

> dput(set.df)
structure(list(Set.name = structure(1:6, .Label = c("set_3_1", 
"set_3_2", "set_3_3", "set_3_4", "set_3_5", "set_3_6"), class = "factor"), 
    Set.size = c(36202L, 31389L, 74322L, 181981L, 204571L, 347844L
    ), TF.number = c(91, 16, 38, 91, 91, 91), Ref.set.size = c(3830L, 
    155L, 725L, 3830L, 3830L, 3830L), False.negatives = c(107L, 
    7L, 100L, 1159L, 1744L, 2310L), Sensitivity = c(0.972062663185379, 
    0.954838709677419, 0.862068965517241, 0.697389033942559, 
    0.544647519582245, 0.39686684073107), Specificity = c(0.0790835553530113, 
    0.296607846658412, 0.296159447758514, 0.300796981749767, 
    0.325487685108514, 0.451174177879625), Precision = c(0.00959662223642798, 
    0.00342695718619029, 0.00608000311296159, 0.0110294421274311, 
    0.0094999544585117, 0.0199195355603025)), row.names = c(NA, 
-6L), class = "data.frame")

和

plot <- ggplot(set.df, aes(key=Set.name, size = Set.size, fill = TF.number, x = Specificity, y = Sensitivity)) + 
  geom_point(colour="#ffffff00") +
  expand_limits(x = 0, y = 0) +
  geom_hline(yintercept = 0.8, linetype = "dotted", colour= 'blue') +
  scale_fill_continuous(low='skyblue', high='midnightblue')

ggplotly(plot, tooltip =  c("Set.name", "Set.size", "TF.number", "Ref.set.size", "False.negatives", "Sensitivity", "Specificity", "Precision"))

输出是:

这些点未以预期的蓝色细微差别显示,我收到以下警告消息:

Warning message:
In L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx] :
  number of items to replace is not a multiple of replacement length

此外,不知何故,磅值图例没有出现。

感谢您的意见!

【问题讨论】:

    标签: r ggplot2 ggplotly


    【解决方案1】:

    主要问题是geom_point() 的fill 美学仅适用于某些形状(有边框的形状)。这不包括默认形状,因此您需要改用 color 美学。至于为什么不显示尺寸图例,ggplotly 尚不原生支持多个图例。见here。

    myplot <- ggplot(set.df, aes(key = Set.name, size = Set.size, color = TF.number, x = Specificity, y = Sensitivity)) + 
      geom_point() +
      expand_limits(x = 0, y = 0) +
      geom_hline(yintercept = 0.8, linetype = "dotted", colour= 'blue') +
      scale_color_continuous(low='skyblue', high='midnightblue')
    
    ggplotly(myplot, tooltip =  c("Set.name", "Set.size", "TF.number", "Ref.set.size", "False.negatives", "Sensitivity", "Specificity", "Precision"))
    

    【讨论】:

    • 哦,非常微妙,非常感谢!关于为什么色标出现在图例部分,而没有尺寸标尺的任何想法?
    • @rioualen - 是的,我在几分钟前编辑了解释。
    猜你喜欢
    • 2019-11-29
    • 2020-11-03
    • 2018-11-08
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 2021-08-04
    相关资源
    最近更新 更多