问题描述
我想用ggplotly()生成一个交互式图.工具提示应显示变量名称.
I want to generate an interactive plot with ggplotly(). The tooltip should show me the name of the variable.
interactive <- ggplotly(pca,dynamicTicks = T,tooltip = c("x","y",label = list))
pca是PCA的可视化.sub是一个包含变量名称的data.frame.
pca is a visualization of a PCA. sub is a data.frame that contains variable names.
sub <- PCA(dataframe)
pca <- fviz_pca_ind(sub, pointsize = "cos2",
pointshape = 21, fill = "#E7B800",
repel = TRUE, # Avoid text overlapping (slow if many points)
geom = c("text","point"),
xlab = "PC1", ylab = "PC2",label = animal_list
)
数据框包含变量名,我希望交互显示在工具提示中. tooltip =
对我没有多大帮助,并且更改pca_individuals中的属性(例如使用label=
或某些方法也不起作用).感谢您的支持.我真的很感谢你的无私行为.
dataframe contains variable names and I want interactive to show those in the tooltip. tooltip =
does not help me much and changing properties in pca_individuals (like with label=
or something is not working either.Thank you for your kind support.I really appreciate your altruistic behaviour.
用于玩耍(实际数据帧要大得多):
For playing around (the actual data frame is muuch bigger):
dataframe <- data_frame("c1"=c(78,89,0),"c2"=c(89,89,34),"c3"=c(56,0,4))
推荐答案
您可以手动执行以下工具提示的内容:
You can manually do the contents of the tooltips as follows:
library(factoextra)
library(plotly)
library(FactoMineR)
dataframe <-
data.frame("c1"=c(78,89,0),"c2"=c(89,89,34),"c3"=c(56,0,4))
res.pca <- PCA(dataframe)
pca <- fviz_pca_ind(res.pca, pointsize = "cos2",
pointshape = 21, fill = "#E7B800",
repel = TRUE,
geom = c("text","point"),
xlab = "PC1", ylab = "PC2")
ggly <- ggplotly(pca)
bggly <- plotly_build(ggly)
bggly$x$data[[1]]$text <-
with(pca$data, paste0("name: ", name,
"</br></br>x: ", x,
"</br>y: ", y,
"</br>coord: ", coord,
"</br>cos2: ", cos2,
"</br>contrib: ", contrib))
bggly
这篇关于在PCA图中带有名称的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!