R ggplot + ggplotly: цветовая гамма не работает - PullRequest
1 голос
/ 30 марта 2020

Начиная с 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"))

, а результат:

output

Точки не отображаются в ожидаемом голубом оттенке, и я получаю следующее предупреждающее сообщение:

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

Кроме того, как-то не отображается легенда о размере точки.

Спасибо за ваш вклад!

1 Ответ

3 голосов
/ 30 марта 2020

Основная проблема заключается в том, что fill эстетика c для geom_point() применима только к определенным фигурам (те, которые имеют границу). Это не включает фигуру по умолчанию, поэтому вам нужно использовать color aestheti c. Что касается того, почему легенда размера не отображается, ggplotly пока не поддерживает несколько легенд. См. здесь .

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"))

enter image description here

...