【发布时间】:2020-04-07 19:13:38
【问题描述】:
我构建了这个漂亮的 geom_point 图,用于标记特定点
我现在正在尝试使用 ggplotly 使所有点(包括粉红色的点)动态化。我收到此警告消息:
在geom2trace.default(dots[[1L]][[1L]],dots[[2L]][[1L]], dots[[3L]][[1L]]) : geom_GeomTextRepel() 尚未实现 巧妙地。如果你想看到这个 geom 的实现,请打开 您的示例代码存在问题
https://github.com/ropensci/plotly/issues
互动剧情看起来还不错,但存在三个问题:
- 字幕消失
- geom_text_repel 的粉色静态文本标签也不见了
- stat_cor 的结果是扭曲的,它们应该显示相关性的 r 和 p 值
是否有解决方法,或者我必须在没有 plotly 的统计图或没有静态标签的交互式图之间进行选择?
我的代码:
p <- df %>%
ggplot(aes(x, y, size = z)) +
geom_point(data=subset(df, a %in% c("a", "b", "c")),
aes(x, y,
text = paste("", a, "\n", #the text label is here for the benefit of ggploty
"x: ", x, "\n", #It is not in the global aes because putting it there removes the entire stat_cor label
"y: ", y, "\n",
"z: ", z, "\n",
sep = "")),
color = "hotpink") +
geom_point(data=subset(df, !(a %in% c("a", "b", "c"))),
aes(x, y,
text = paste("", a, "\n", #the text label is here for the benefit of ggploty
"x: ", x, "\n", #It is not in the global aes because putting it there removes the entire stat_cor label
"y: ", y, "\n",
"z: ", z, "\n",
sep = "")),
color = "steelblue") +
geom_text_repel(data=subset(df, a %in% c("a", "b", "c")),
aes(label=a), color="hotpink", size=5, fontface ="bold", point.padding = TRUE) +
ggtitle("Nice Plot!",
subtitle = "Point Sizes Vary Based On z") +
xlab("x label") + ylab("y label") +
labs(size = "z label") +
theme_minimal() +
theme(plot.title = element_text(face = "bold", color = "darkgrey", hjust = .5, size = 15),
plot.subtitle = element_text(face = "italic", color = "darkgrey", hjust = .5, size = 13),
legend.position = "top",
legend.title = element_text(face = "bold", color = "steelblue", size = 12),
legend.text = element_text(face = "bold", color = "steelblue", size = 12),
axis.text = element_text(face = "bold", color = "darkgrey", hjust = .5, size = 12),
axis.title = element_text(face = "bold", color = "darkgrey", hjust = .5, size = 12)) +
stat_cor(method = "pearson", label.x = 10, label.y = 90, color = "steelblue", size =6)
p #shows subtitle, and labels pink poiints with geom_text_repel
# Three issues:
#1) subtitle dissappears
#2) pink static text labels from geom_text_repel are also gone
#3) the results from stat_cor are warped, they should show the r and pvalues from the correlation
ggplotly(p, tooltip = "text") %>%
config(displayModeBar = F)
【问题讨论】:
标签: r ggplot2 text label ggplotly