我正在生成一个SVG分面图。我希望在悬停时出现工具提示。我在ggplot / geom_point中使用
产生了一个警告...
我应该避免使用此功能,还是有更好、更可靠的方法来实现此效果?
text
美学来制作工具提示文本。产生了一个警告...
警告:忽略未知的美学:text
。尽管有警告,但它确实按照我在geom_point
的下定义的方式生成了工具提示。然而,一旦图表中的分面数量超过21个,工具提示仅出现在点的子集中。它似乎不可靠。但是,删除text
美学始终会为所有点在任何数量的分面上产生默认工具提示。当包含text
美学时,生成的工具提示是我定义的特定文本和默认文本的组合,看起来像这样...截图工具提示... 不理想,但至少包含了我想要显示的信息,特别是将速率/'000作为实际值而不是对数值。我应该避免使用此功能,还是有更好、更可靠的方法来实现此效果?
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)