ggplot geom_point 忽略未知的美学:文本问题?

Lia*_*rey 3 text r ggplot2

我正在生成 SVG 分面图。我希望将鼠标悬停在点上时出现工具提示。我正在使用textggplot/geom_point 中的美学来制作工具提示文本。

产生警告Warning: Ignoring unknown aesthetics: text.... 尽管有警告,它实际上会生成一个工具提示,正如我在下面的sprintfof中定义的那样geom_point。但是,一旦图表中的面数超过 21,工具提示将仅针对部分点出现。这似乎不可靠。然而,消除美感总是会导致任意数量的面上的所有text出现默认的工具提示。当包含美学时,生成的工具提示是默认文本和我定义的定制文本的组合,看起来像这样...工具提示的屏幕截图...并不理想,但至少它包含我想要显示的信息,特别是Rate/'000 作为实际值而不是对数值。text

我应该避免这个功能还是有更好、更可靠的方法来实现这个效果?

    p <- ggplot(data=df.data_chart_category
               ,aes(x=TourDate, y=rate_per_thousand_lifts, group=key, colour=factor(key))
               ,environment = environment()
        ) +
        geom_point(aes(size = size, text = sprintf("Rate/'000: %s<br>Misses: %s<br>Hits: %s<br>Total Lifts: %s", rate_per_thousand_lifts, misses, hits, total_tour_count)), alpha=0.4) +
        scale_size(name = "Bin count", breaks = c(10, 50, 100, 500, 800, 1000), range = c(1,12)) +
        scale_color_manual("", values = c("Lifter1" = "red", "Lifter2" = "green", "Lifter3" = "lightblue", "Lifter4" = "purple", "NoLifter" = "cyan", "GPS" = "darkgrey")) +
        guides(colour = guide_legend(override.aes = list(size=10))) +
        facet_wrap(as.formula(paste("~", facet_wrap_column_name)), ncol=number_of_facet_columns) +
        labs(x = x_axis_label, y = snr_y_axis_label, title = snr_chart_title, subtitle = snr_chart_subtitle, caption = snr_chart_caption, color="Lifter") +
        theme_few() +
        theme(axis.text.x = element_text(angle=90, vjust=-0.01)) + 
        theme(axis.title = element_text(size = axis_font_size)) + 
        theme(plot.title = element_text(color = '#666666', 
                                  face = 'bold',
                                  size = title_font_size,
                                  hjust = 0)) + 
        scale_y_log10()

    pp <- ggplotly(p)
    htmlwidgets::saveWidget(widget=pp, file="index.html", selfcontained=FALSE)
Run Code Online (Sandbox Code Playgroud)